In order to understand the Google Maps API v3 integration, we first need to know that It depends upon Google Geocoding API aswell.
What is Geocoding API?
//PHP START <?php // Storing the formatted address in a variable "$address" $address = "1600 Amphitheatre Parkway, Mountain View, CA"; // Next we need to replace the spaces of the address with a "+" sign $address = str_replace(" ", "+", $address); // Setting Geocoding URL to which we need to send an API Call and appending the address $jsonURL = "http://maps.googleapis.com/maps/api/geocode/json?address=".$address."&sensor=false"; // Next initiating cURL $geocurl = curl_init(); //Next setting cURL options/parameters curl_setopt($geocurl, CURLOPT_URL, $jsonURL); curl_setopt($geocurl, CURLOPT_HEADER, 0); curl_setopt($geocurl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); curl_setopt($geocurl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($geocurl, CURLOPT_RETURNTRANSFER, 1); // Executing cURL call and storing returned data into a variable $data = curl_exec($geocurl); // The returned result is in json format, we need to decode json $data = json_decode($data); // After decoding, we can now access latitude numeric value and longitude numeric value as: $latitude = $data->results->geometry->location->lat; $longitude = $data->results->geometry->location->lng; ?>
View PHP code on Github
Getting your Google Maps V3 API Unique KEYNext , you need to get your google maps v3 API key: Click Here to Get your Google Maps API Key. Now log in with your Google account credentials or create a new account if you do not have one already. You will now see the Google API's Console Dashboard:
Now click on "Services" on the left menu. You will see a list of available API's that you can activate for your developer's account. For now we just need to activate "Google Maps API v3". Have a look at the screenshot below:
Next Accept the terms and conditions of Google and that is it, now you have been registered to get your unique API access. To get the key, simply click on the "API Access" on the left navigation menu. Have a look at the screenshot below:
Now that you have obtained your unique API access key, finally we need to give API a call using this key for authorization and actually show the map within the required division on the web page.
Finally, Create a division with ID named "map" on your webpage wherever you want the Google map to be rendered on page. Example: <div id="map"></div>
That is it, now your Google Map is fully functional. Also note that the size of the Google map will depend upon the width and height of the "map" div that you have defined/styled within the stylesheet.
If you have any problems integrating Google Maps API v3, please let me know via comment box below, I would be more than happy to help you out!