Scott Scott - 1 year ago 209
Javascript Question

Get LatLng from Zip Code - Google Maps API

All I want is some simple example code that shows me how to obtain a latlng element from an inputted zip code OR a city/state.

Answer Source

Couldn't you just call the following replaceing the {zipcode} with the zip code or city and state{zipcode}

Google Geocoding

Here is a link with a How To Geocode using JavaScript: Geocode walk-thru. If you need the specific lat/lng numbers call or geometry.location.lng() (API for google.maps.LatLng class)

EXAMPLE to get lat/lng:

    var lat = '';
    var lng = '';
    var address = {zipcode} or {city and state};
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
         lat = results[0];
         lng = results[0].geometry.location.lng();
      } else {
        alert("Geocode was not successful for the following reason: " + status);
    alert('Latitude: ' + lat + ' Logitude: ' + lng);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download