Google Maps API V3 Javascript Basic Example

/ Published in: JavaScript
Save to your folder(s)

This javascript will create a google map on the div with the ID "the_map" and centered on an address with a marker on it. In this example the address is for Jet City Improv. More information on setup and customization at the link.

Copy this code and paste it in your HTML
  1. window.onload = function(){
  2. var geocoder = new google.maps.Geocoder();
  3. geocoder.geocode({'address':'5510 University Way NE Seattle, WA 98105'},function(result,status){
  4. if(status==google.maps.GeocoderStatus.OK){
  5. var map = new google.maps.Map(document.getElementById("the_map"),{
  6. 'center': result[0].geometry.location,
  7. 'zoom': 14,
  8. 'streetViewControl': false,
  9. 'mapTypeId': google.maps.MapTypeId.TERRAIN,
  10. 'noClear':true,
  11. });
  12. new google.maps.Marker({
  13. 'map': map,
  14. 'position': result[0].geometry.location,
  15. });
  16. }else{
  17. alert('Address not found!');
  18. }
  19. });
  20. }


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.