Hello, please sign in or register
You are here: Home

Google maps app

Google maps example

Finding addresses based upon a string. E.g. "Hampstead, London"

To search Google Map we need to add a geocoding method. 

Example http://code.google.com/apis/maps/documentation/examples/geocoding-extraction.html.

Get the first result for the address "Hampstead, London", e.g.
var geocoder = new GClientGeocoder();
geocoder.getLocations('Hampstead, London', function(res){alert(res.Placemark[0].address);});

Put this into a link and we now get a better address Hampstead, London.

Finding the coordinates and add Marker to the map

The API method getLocations also returns coordinates. To get these we call

res.Placemark[0].Point.coordinates[1] 
res.Placemark[0].Point.coordinates[0]

I.e. replacing "res.Placemark[0].address" in the above example. Thus we get Hampstead, London coordinates.

Now we want to create a marker on the map. Using the cooridinates we just acquired we do...

map.addOverlay(new GMarker(new GLatLng(res.Placemark[0].Point.coordinates[1],
res.Placemark[0].Point.coordinates[0])));

Add a marker over Hampstead

Center the map to Coordinates

map.panTo(new GLatLng(res.Placemark[0].Point.coordinates[1], 
                    res.Placemark[0].Point.coordinates[0]));

E.g. panTo "Hampstead, London"


Comments

Title*
Comment

Prove you are not a robot

To prove you are not a robot, please type in the six character code you see in the picture below
Security confirmation codeI can't see this!
Contact
Name*
Email never shown*
Home Page

Author

Andrew Dodson
Since:Feb 2007

Comment | flag

Categories

Bookmark and Share