Guest User

Untitled

a guest
Jan 15th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. function getTown(latitude,longitude){
  2.  
  3. // Define Geocoding
  4. var geocoder = new google.maps.Geocoder();
  5.  
  6. // Using the longitude / latitude get address details
  7. var latlng = new google.maps.LatLng(latitude,longitude);
  8.  
  9. geocoder.geocode({'latLng': latlng}, function(results, status){
  10.  
  11. // If response ok then get details
  12. if (status == google.maps.GeocoderStatus.OK) {
  13. var town = results[1].address_components[1].long_name;
  14.  
  15. return town; // Returns Norwich when alerted using the e.g below.
  16. }
  17. });
  18. }
  19.  
  20. getTown(52.649334,1.288052);
  21.  
  22. var theTown = null;
  23. function getTown(latitude,longitude){
  24.  
  25. // Define Geocoding
  26. var geocoder = new google.maps.Geocoder();
  27.  
  28. // Using the longitude / latitude get address details
  29. var latlng = new google.maps.LatLng(latitude,longitude);
  30.  
  31. geocoder.geocode({'latLng': latlng}, function(results, status){
  32.  
  33. // If response ok then get details
  34. if (status == google.maps.GeocoderStatus.OK) {
  35. var town = results[1].address_components[1].long_name;
  36.  
  37. theTown = town; // Returns Norwich when alerted using the e.g below.
  38. }
  39. });
  40. }
Add Comment
Please, Sign In to add comment