篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript Google Map自定义,可点击标记的标记相关的知识,希望对你有一定的参考价值。
<div id="map"></div>
<script type="text/javascript">
// Create a base icon
var baseIcon = new GIcon();
baseIcon.image = "images/red_marker.png";
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);
function createMarker(point, index, city) {
var letteredIcon = new GIcon(baseIcon);
markerOptions = {
icon:letteredIcon,
labelText: index,
labelClass: "glabel",
labelOffset: new GSize(-6, -32)
};
var marker = new LabeledMarker(point, markerOptions);
// Go to town page if icon is clicked
GEvent.addListener(marker, "click", function() {
window.location = city + ".html"
});
return marker;
}
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(35.600, -82.554), 8);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
//Change this to set base map to terrain
//map.setMapType(G_PHYSICAL_MAP);
//map.addMapType(G_PHYSICAL_MAP);
//Markers, label text, and city name for each marker
// GLatLng defined the point, the label text is overlayed on the marker, and the city name is the pagename to link
// example: map.addOverlay(createMarker(new GLatLng(lat, lng), label, city-name))
map.addOverlay(createMarker(new GLatLng(35.5, -82.57),1,'Asheville'))
map.addOverlay(createMarker(new GLatLng(36.15, -81.89),2,'Banner-Elk'))
map.addOverlay(createMarker(new GLatLng(35.6, -82.34),3,'Black-Mountain'))
map.addOverlay(createMarker(new GLatLng(36.13, -81.67),4,'Blowing-Rock'))
}
</script>
以上是关于JavaScript Google Map自定义,可点击标记的标记的主要内容,如果未能解决你的问题,请参考以下文章