How to Use the Street Address Instead of Lat/Long in Google Maps API

If you don't know a street address' exact latitude and longitude, you can determine it using the Google Maps API geocoding service. Using the GClientGeocoder object, you can convert an address string into a precise set of latitude and longitude coordinates and mark those coordinates on a Google Map.

Instructions

    • 1

      Open your HTML file and locate the javascript referencing your Google map.

    • 2

      Initialize the GClientGeocoder object by typing:

      var GetAddress = new GClientGeocoder ( );

    • 3

      Translate the street address to geographic coordinates by typing:

      function showAddress (address_example) {
      geocoder.getLatLng (address_example); }

    • 4

      Mark the coordinates on the map by typing:

      var markCoordinates = new GMarker (address_example);
      map.AddOverlay(markCoordinates);

    • 5

      Save your HTML file and upload to your web server for testing. You should see a Google Map with a pin-point marker on the coordinate for the street address.

Tips & Warnings

  • The only drawback of calling the GClientGeocoder object is that the function depends on the speed of Google servers to process and convert the address. If speed is a factor in creating your Google Maps, use another method to calculate the address' latitude and longitude.

Related Searches:

References

Comments

Related Ads

Featured