Google Maps: how to get country, state/province/region, city given a lat/long value?

What you are looking for is called reverse geocoding. Google provides a server-side reverse geocoding service through the Google Geocoding API, which you should be able to use for your project. This is how a response to the following request would look like: http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false Response: { “status”: “OK”, “results”: [ { “types”: [ “street_address” ], … Read more

Given the lat/long coordinates, how can we find out the city/country?

Another option: Download the cities database from http://download.geonames.org/export/dump/ Add each city as a lat/long -> City mapping to a spatial index such as an R-Tree (some DBs also have the functionality) Use nearest-neighbour search to find the closest city for any given point Advantages: Does not depend on an external server to be available Very … Read more

How can I measure distance and create a bounding box based on two latitude+longitude points in Java?

Here is a Java implementation of Haversine formula. I use this in a project to calculate distance in miles between lat/longs. public static double distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; // miles (or 6371.0 kilometers) double dLat = Math.toRadians(lat2-lat1); double dLng = Math.toRadians(lng2-lng1); double sindLat = Math.sin(dLat / … Read more

Getting distance between two points based on latitude/longitude

Update: 04/2018: Vincenty distance is deprecated since GeoPy version 1.13 – you should use geopy.distance.distance() instead! The answers above are based on the Haversine formula, which assumes the earth is a sphere, which results in errors of up to about 0.5% (according to help(geopy.distance)). Vincenty distance uses more accurate ellipsoidal models such as WGS-84, and … Read more