I'm using PHP and want to embed a small Google map on one of my pages using a full address. So I have the address of a location, and want to use this address to create the map. I do not know any coordinates of the location like the latitude and longitude; only the full address is known. How can I do this?
<script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg&sensor=true_or_false" type="text/javascript"></script> <script type="text/javascript"> var map = null; var geocoder = null; function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(37.4419, -122.1419), 13); geocoder = new GClientGeocoder(); showAddress("<?php echo "white house"; ?>"); } } function showAddress(address) { if (geocoder) { geocoder.getLatLng( address, function(point) { if (!point) { alert(address + " not found"); } else { map.setCenter(point, 13); var marker = new GMarker(point); map.addOverlay(marker); marker.openInfoWindowHtml(address); } } ); } } initialize(); </script> <div id="map_canvas"></div> Code (markup): Please remember to insert your Google Maps API Key in the script src tag.
How can I get the Google Maps API Key when it is saying to enter website's URL at which it will be used? I am still developing the website and have not registered a domain name at the moment. Do I just enter: http://localhost/ for the URL since it is hosted on my development machine or what can I do to make it work?
Yes, for the time being you can use http://localhost/yourprojectname for getting the API from google. After completion of the project and geeting the live domain, get the actual API using your original URL and then replace the new API key to the old one.
I got a new Maps API key from Google and added it to the script above, but my <div> is empty. I entered http://localhost when they asked me for the website URL. No map is loaded at all. I created the div <div id="map_canvas"></div> in the <body> of my page but nothing is loaded in it. The script above should load and initial map using 37.4419, -122.1419 as coordinates, but nothing gets displayed. Is the script above correct or could it be that the key I got from Google is not good? I found the error. The script pasted above was calling initialize() without assigning it to body onload.
The latest version of google maps api does not need a key. I think this http://marcgrabanski.com/tag/google-maps will help you.