Reputation: 5093
I want to create LatLngBounds for 50Mile radius wrt. current location. to use with google places api.
Right now, I do following an example online
//Southwest corner to Northeast corner.
LatLngBounds bounds = new LatLngBounds(
new LatLng(39.906374, -105.122337),
new LatLng(39.949552, -105.068779)
);
Can you provide pointers?
Update:
I used this as answer:
How to convert a LatLng and a radius to a LatLngBounds in Android Google Maps API v2?
Upvotes: 0
Views: 998
Reputation: 10621
I assume, that you know how to figure out the user's location. There is plenty of info on this topic.
So, the main problem is figuring out the corners to use as your bounds. This is known as a direct geodesic problem (see: https://en.wikipedia.org/wiki/Geodesics_on_an_ellipsoid). You have a couple of ways to solve it:
Use a java library (http://geographiclib.sourceforge.net/html/java/) to calculate the coordinates of corners using the following method:
Geodesic.WGS84.Direct(lat1, lon1, azi1, s12)
(see the docs: http://geographiclib.sourceforge.net/html/java/net/sf/geographiclib/Geodesic.html)
Note, that you have to figure out the azimuth along the way.
Use the built in android.location.Location class. It has a static method 'distanceBetween' that take the coordinates of two points and calculates the distance between them.
The point here is to use the 'Divide and Conquer Algorithm' to find the top/bottom latitudes and left/right longitudes of your bounding rect.
Use fixed values to convert distance into approximate lat/lng degrees if the accuracy is not an issue.
Upvotes: 3