Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve distance from visible part of Google map

Tags:

I want to draw a static circle over a map with Google Maps. When the user pinches, the map will zoom in/out.

I need to know the map radius (related to the area contained in the circle) and change the seekbar at the bottom accordingly.

Does anybody know a solution how to retrieve the distance from the left to the right screen edge? I didn't find anything at the Google Maps API doc.

Something like this:

enter image description here

like image 301
Ale Avatar asked Dec 06 '13 11:12

Ale


People also ask

How do you see how far something is from somewhere else?

Google Maps is making it a whole lot easier to find out exactly how far apart any two (or more) points are on a map. As of yesterday, you can now right click anywhere on Google Maps on the web and choose "measure distance" to bring up a digital ruler that'll tell you just how far away its final point is.

Is Google Distance Matrix API free?

The Distance Matrix API uses a pay-as-you-go pricing model.

What is used to calculate the viewport of the Google Maps?

Latitude + (result. Span. Latitude/2); double swLon = result.


1 Answers

using VisibleRegion you can get the all corner cordinates and also the center.

VisibleRegion vr = mMap.getProjection().getVisibleRegion(); double left = vr.latLngBounds.southwest.longitude; double top = vr.latLngBounds.northeast.latitude; double right = vr.latLngBounds.northeast.longitude; double bottom = vr.latLngBounds.southwest.latitude; 

and you can calcuate distance from two region by this

Location MiddleLeftCornerLocation;//(center's latitude,vr.latLngBounds.southwest.longitude) Location center=new Location("center"); center.setLatitude( vr.latLngBounds.getCenter().latitude); center.setLongitude( vr.latLngBounds.getCenter().longitude); float dis = center.distanceTo(MiddleLeftCornerLocation);//calculate distane between middleLeftcorner and center  

enter image description here

like image 138
Md. Monsur Hossain Tonmoy Avatar answered Nov 09 '22 03:11

Md. Monsur Hossain Tonmoy