From GamingWiki
Jump to: navigation, search
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);
geocoder = new google.maps.Geocoder();
 
 
getMarkerList();
 
getMarkerList();
 
}
 
}
Line 33: Line 33:
 
google.maps.event.addDomListener(window, 'load', initialize);
 
google.maps.event.addDomListener(window, 'load', initialize);
  
// Helper function
+
/**
function addMarkerByLatLng(lat, lng, title, description) {
+
* Add a marker to the map
var latlng = new google.maps.LatLng(lat, lng);
+
*/
 +
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); });
return 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(result, status) {
+
geocoder.geocode({'address':address}, function(results, status) {
if (status != google.maps.Geocoder.OK) {
+
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);
} else {
 
var marker = new google.maps.Marker({position:latlng, map:map, title:name});
 
google.maps.event.addListener(marker, "click", function() { infowindow.open(map,marker); });
 
 
}
 
}
 
});
 
});

Revision as of 01:25, 25 October 2010