From GamingWiki
Line 26: | Line 26: | ||
mapTypeId: google.maps.MapTypeId.ROADMAP | mapTypeId: google.maps.MapTypeId.ROADMAP | ||
} | } | ||
+ | geocoder = new google.maps.Geocoder(); | ||
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); | map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); | ||
− | |||
getMarkerList(); | getMarkerList(); | ||
} | } | ||
Line 33: | Line 33: | ||
google.maps.event.addDomListener(window, 'load', initialize); | google.maps.event.addDomListener(window, 'load', initialize); | ||
− | // | + | /** |
− | function | + | * Add a marker to the map |
− | + | */ | |
+ | function addMarker(latlng, title, description) { | ||
var marker = new google.maps.Marker({position:latlng, map: map, title:title}); | var marker = new google.maps.Marker({position:latlng, map: map, title:title}); | ||
var infowindow = new google.maps.InfoWindow({ | var infowindow = new google.maps.InfoWindow({ | ||
Line 41: | Line 42: | ||
}); | }); | ||
google.maps.event.addListener(marker, "click", function() { infowindow.open(map,marker); }); | google.maps.event.addListener(marker, "click", function() { infowindow.open(map,marker); }); | ||
− | + | } | |
+ | /** | ||
+ | * Add a marker with a lat/lng pair | ||
+ | */ | ||
+ | function addMarkerByLatLng(lat, lng, title, description) { | ||
+ | var latlng = new google.maps.LatLng(lat, lng); | ||
+ | addMarker(latlng, title, description); | ||
} | } | ||
Line 49: | Line 56: | ||
function addMarkerByAddress(address, title, description) { | function addMarkerByAddress(address, title, description) { | ||
if (geocoder) { | if (geocoder) { | ||
− | geocoder.geocode(address, function( | + | geocoder.geocode({'address':address}, function(results, status) { |
− | if (status | + | if (status == google.maps.GeocoderStatus.OK) { |
+ | var latlng = results[0].geometry.location; | ||
+ | addMarker(latlng, title, description); | ||
+ | } else { | ||
alert(address + " not found: "+result+"; "+status); | alert(address + " not found: "+result+"; "+status); | ||
− | |||
− | |||
− | |||
} | } | ||
}); | }); |
Revision as of 01:25, 25 October 2010