I just need to know how to go about getting a postcode from the longitude and latitude.
Im using the google maps api to get the long and lat based on a search such as ‘manchester’ i then need a to get the postcode from this to query my database.
My code so far is
function getLatLng()
{
var localSearch = new google.maps.Geocoder();
var postcode = $("#address").val();
localSearch.geocode({ 'address': postcode },
function(results, status) {
if (results.length == 1) {
var result = results[0];
var location = result.geometry.location;
}
else
{
$("#error").html("Address not found");
}
});
}
What you’re trying to do is (an example of) ‘Reverse Geocoding’
See:
Google reverse geocoding – how to snap to nearest full postcode
Specifically a link to:
https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-reverse