Google Maps V3 GeoCoding Example

Today I was working on a real estate search wrapper idea and trying to integrate Google Maps. I wanted to use there Javascript API for mapping but needing to translate the addresses to longitude and latitude aka GeoCoding. Turns out Google of course has an API for this but I didn’t find a straight forward example right away so I figured I would post one. Minor disclaimer on this, its the SIMPLEST possible example to just take one address and turn it into a longitude and latitude (visit here if you need more info on the API). Hopefully this is helpful to folks.

Script Include

Before using the below code you’ll want to add a script include within the head element of your HTML page first.

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

The Code

 

1:  var geocoder = new google.maps.Geocoder();  
2:  var results = geocoder.geocode(  
3:    {  
4:      address: "Duke University Durham, NC 27708"  
5:    },   
6:    function callback(results){  
7:      alert(results[0].geometry.location);  
8:    }  
9:  );  
Advertisements

Tags: , , ,

3 Responses to “Google Maps V3 GeoCoding Example”

  1. Undertec Blog Says:

    Google Maps: Geografische Koordinaten bestimmen…

    Wer aus Google Maps geografische Koordinaten wie Längen- und Breitengrade wie aus normalen Karten ermitteln möchte, der kann “Google Maps API Example: Simple Geocoding” verwenden. Dabei kann man wie die untenstehende Beispiel zeigen, alles mögliche d…

  2. Anonymous Says:

    This e.g. really helped me. I was looking for such kind of simple e.g.

    Thanks,
    Jyotsna

  3. Anonymous Says:

    This e.g. really helped me as I was looking for such kind of simple e.g.

    Thanks,
    Jyotsna

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: