October 2, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Building a Geocoding Web Service

  • November 28, 2005
  • By Jason Gilmore
  • Send Email »
  • More Articles »

Displaying the Google Map

Now that the coordinates have been retrieved, all you need to do is pass them into the appropriate Google Maps API method. To do so, paste the following code into the PHP Web services client (geocodeclient.php), being sure to place it below the closing PHP delimiter (?>). You'll also need to replace ADD_YOUR_KEY_HERE with your Google Maps API key. If you haven't yet registered for your key, see the instructions found in the opening installment of this series.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script src="http://maps.google.com/maps?file=api&v=1
         &key=ADD_YOUR_KEY_HERE" type="text/javascript">
    </script>
  </head>
  <body>
    <div id="map" style="width: 400px; height: 300px"></div>
    <script type="text/javascript">
    //<![CDATA[
    var map = new GMap(document.getElementById("map"));
    map.centerAndZoom(
    new GPoint(<?php echo $longitude;?>, <?php echo $latitude;?>), 3);
    var point = 
    new GPoint(<?php echo $longitude;?>, <?php echo $latitude;?>);
    var marker = new GMarker(point);
    map.addOverlay(marker);
    //]]>
    </script>
  </body>
</html>

Execute the geocodeclient.php script anew and you'll see the following map:

Conclusion

There you have it! A custom, end-to-end Web mapping solution built entirely from open source and freely available services.

About the Author

W. Jason Gilmore (http://www.wjgilmore.com/) is the open source editor for Apress. He's the author of the best-selling Beginning PHP 5 and MySQL: Novice to Professional (Apress, 2004. 758pp.). Along with Robert Treat, Jason is the co-author of the forthcoming Beginning PHP 5 and PostgreSQL 8: From Novice to Professional, due out at the conclusion of 2005. Jason loves receiving e-mail, so don't hesitate to write him at wjATwjgilmore.com.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel