Dear Bart, Thank you for your reply.
Sreejith.R On Tue, Aug 11, 2009 at 8:03 PM, Bart Van der Donck <[email protected]> wrote: > > sreejith R wrote: > > > Hello Bart, > > > > First of all thank you for your reply. > > I can't get your code. I am new in this technology. > > I am doing my project in PHP and I am using <div> to load > > the map.That is > > <div id="map" style="width: 700px; height: 500px"></div> > > var map = new GMap2(document.getElementById("map")); > > So what will I do. > > Well, you could code out the whole thing too. What you describe, is > known as "reversed geo-coding"; the mapping of addresses to lat/lon- > pairs (and then correspondingly show them on the map). Google Maps > knows 'GClientGeocoder()' for this. So here is a second possibility > for your PHP-file: > > -------------------------------------------------------------------- > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > "http://www.w3.org/TR/html4/loose.dtd"> > <html> > <head> > <title>Reverse geocoding</title> > <script type="text/javascript" > src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=XX"> > </script> > <script type="text/javascript"> > var map = null; > var geocoder = null; > function initialize() { > if (GBrowserIsCompatible()) { > map = new GMap2(document.getElementById('map')); > map.setCenter(new GLatLng(50, 5), 3); > map.addControl(new GSmallMapControl()); > geocoder = new GClientGeocoder(); > } > } > > function getLatLng(point) { > var matchll = /\(([-.\d]*), ([-.\d]*)/.exec( point ); > if (matchll) { > var lat = parseFloat( matchll[1] ); > var lon = parseFloat( matchll[2] ); > lat = lat.toFixed(6); > lon = lon.toFixed(6); > } > else { > var message = "Error extracting info from: " + point; > var messagRoboGEO = message; > } > return new GLatLng(lat, lon); > } > > function searchPlace(place) { > if (geocoder) { > map.clearOverlays(); > geocoder.getLatLng(place, function(point) { > if (!point) { > alert(place + " not found"); > } > else { > var latLng = getLatLng(point); > var marker = new GMarker(point); > map.addOverlay(marker); > map.panTo(latLng); > } > }); > } > } > </script> > </head> > <body onload="initialize();" onunload="GUnload();"> > <div id="map" style="width: 500px; height: 300px"></div> > <form onSubmit="return false;"> > <select size="1" name="loc" > onChange="if (this.value != '') { searchPlace(this.value); }"> > <option value="">Choose a place</option> > <?php > // your place names from Postgis go here... > print '<option value="New York">New York</option>'; > print '<option value="Madrid">Madrid</option>'; > print '<option value="Brussels">Brussels</option>'; > ?> > </select> > </form> > </body> > </html> > -------------------------------------------------------------------- > > 'XX' should be replaced by your real API Key. In any case, I would > also add the country in the select list (like 'Brussels, Belgium'). > You got to admit that my first solution was a bit simpler, no ? :-) > > -- > Bart > > > -- Sreejith.R --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Maps-API?hl=en -~----------~----~----~----~------~----~------~--~---
