Googlemaps标记不加载
我对这个网站不熟悉新的谷歌地图和相当新的JavaScript,所以请有点耐心。Googlemaps标记不加载
我一直负责将一些谷歌地图界面添加到一个站点我管理员,所以我跟着谷歌教程,我得到尽可能显示地图,地理编码地址字符串和设置标记。 继承人问题,第一个地址编码指针总是出现,但其余的只是间歇性出现(通常在第一次加载或几次重新加载后)。 Firebug的报告以下错误:
"Invalid value for property : (53.3800136, -1.475428500000021) on line 28 of main.js"
我想我已经找到了问题的功能,脚本似乎在这一点上停止加载其他标记间歇性熄火。 我已经尝试过所有我能找到的相关解决方案,而且现在还没有工作我很难接受任何人的帮助吗?我的继承人参考代码:
function load_map() {
var startLatLng = new google.maps.LatLng(52.485809,-1.888783);
// create a new Google latLang marker object with co-ords for
// start location
// create a JASON object to store map configuration
var config = {
zoom: 5,
center: startLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), config);
// initialise the map passing the display divs id and the config
// object
var startMarker = new google.maps.Marker({
position: startLatLng,
map: map
})
// create a new marker object for start location
startMarker.setMap(map);
// Add the marker to the map
geocodeAddress("ARM Ltd Rockingham Court 152 Rockingham Street Sheffield Great Britain");
geocodeAddress("Centrum House 36 Station Road Egham Surrey");
geocodeAddress("Pipers Way Swindon United Kingdom");
// call the geocoding function to add markers to the map hard coded right now for testing
// but to be pulled from a DB in future
}
/*
* This function loads a marker overlay on to the location provided
* and calls the addInfoWindow function to add an info window to it
*
* @ param a google location object representing the location at which
* the marker is to be placed
* @ param a String variable representing the information to be attached
* to the window.
*/
function loadMarker(location,windowText) {
var tempMarker = new google.maps.Marker({
position: location,
map: map
});
addInfoWindow(windowText,tempMarker);
// add an information window anchored on the marker
tempMarker.setMap(location); // seems to work ok up to this point.
// add the marker to the map at this location
}
/*
* A function to geocode the string type address passed into usable
* lat lng type co-ords
* @ param a String representing the address to be geocoded
*/
function geocodeAddress (address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
loadMarker(results[0].geometry.location,"Info here");
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
/*
* This function adds an info window to each marker and allows it
* to be activated on click.
* @Param
*/
function addInfoWindow (infoText,marker) {
var contentString = infoText;
var tempInfoWindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function() {
tempInfoWindow.open(map,marker);
});
}
// initialise all the page components by calling there load functions
// called using a standard body onload to intilise the map
function init() {
load_map();
}
53行错误地引用的location
代替map
更改您的代码从:
tempMarker.setMap(location);
到
tempMarker.setMap(map);
谢谢andresf现在完美地工作:-),知道它必须是简单的。 – user1079178 2012-02-22 09:26:45
您可能希望将答案标记为正确,以便其他人更容易找到答案。它也会帮助我的业力。 – andresf 2012-02-22 19:02:48
它会帮助你将所有代码放在一起,调试一个函数,而不用调用它的上下文难。如果你不能直接托管它,你可以尝试搭建一个jfiddle。 – 2012-02-21 16:16:59