Using a Projection class

Google maps provides a Projection class, which has some useful methods. The fromScreenLocation() method converts screen pixels in point coordinates to LatLng coordinates.

The toScreenLocation() method converts the LatLng coordinates to the screen pixel point coordinates.

The getVisibleRegion() method returns the VisibleRegion object from which we can obtain LatLngBounds.

Let's see an example where we are going to convert a screen pixel Point coordinate, (100,100), to a LatLng coordinate when the camera changes. From this, we get the visible region and display the north-east and south-west corners of the LatLng coordinate.

Then, when the map is clicked on, we obtain the LatLng coordinate of the clicked location and convert ...

Get Learning Android Google Maps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.