檢查下面的腳本,確保使用api添加谷歌地圖
// When the window has finished loading create our google map below
google.maps.event.addDomListener(window, 'load', init);
function init()
{
// Basic options for a simple Google Map
// For more options see: https://developers.google.com/maps/documentation //javascript/reference#MapOptions
var mapOptions = {
// How zoomed in you want the map to start at (always required)
zoom: 4,
// The latitude and longitude to center the map (always required)
center: new google.maps.LatLng(25.985448,52.7994103),
// Main map location
navigationControl: false,
mapTypeControl: false,
scaleControl: false,
draggable: false,
scrollwheel: false,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
position: google.maps.ControlPosition.BOTTOM_LEFT
},
// How you would like to style the map.
// This is where you would paste any style found on Snazzy Maps.
styles: []
};
// Get the HTML DOM element that will contain your map
// We are using a div with id="map" seen below in the
<body>
var mapElement = document.getElementById('googlemap');
// Create the Google Map using our element and options defined above
var map = new google.maps.Map(mapElement, mapOptions);
// address content Kuwait
var location1 = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Location1 name</h1>'+
'<div id="bodyContent">'+
'<p> Location 1 content' +
'</p>'+
'</div>'+
'</div>';
var infolocation1 = new google.maps.InfoWindow({
content: location1
});
// Location Kuwait
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(29.363765,47.966278),
map: map,
title: ''
});
marker1.addListener('click', function() {
infolocation1.open(map, marker1);
});
// address content Kuwait
var location2 = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">
Location2 name</h1>'+
'<div id="bodyContent">'+
'<p> Location 2 content' +
'</p>'+
'</div>'+
'</div>';
var infolocation2 = new google.maps.InfoWindow({
content: location2
});
// Location Kuwait
var marker2 = new google.maps.Marker({
position: new google.maps.LatLng(29.363765,47.966278),
map: map,
title: ''
});
marker2.addListener('click', function() {
infolocation2.open(map, marker2);
});
}
</pre>
antyrat,對於拼寫錯誤感到抱歉。它確實是GEvent.addListener(markers [i],..),現在我編輯它。仍然不起作用。 謝謝 v.srinath – 2010-03-05 04:00:23
我更新我的答案,現在試試。 – antyrat 2010-03-05 11:04:10
你可以顯示XML文件的例子嗎?我沒有看到你創建標記的位置。它必須是這樣的:var marker = new GMarker(point); var point = new GLatLng(lat,lng); – antyrat 2010-03-05 11:06:17