Javascript 在Google Maps API上显示存储的标记

Javascript 在Google Maps API上显示存储的标记,javascript,php,ajax,google-maps-api-3,activexobject,Javascript,Php,Ajax,Google Maps Api 3,Activexobject,首先,我刚开始使用GoogleMapsAPI(并使用AJAX)。。。制造了很多问题。。。解决了这些问题。但现在我似乎被卡住了 我一直在关注Google开发者关于如何创建商店定位器()的教程——写得很好,解释得也很好——但是为了我的需要,我对它做了一些修改 现在我得到了错误 InvalidValueError:setMap:不是Map的实例,也不是实例 街景全景 创建错误的函数是: function downloadUrl(url,callback) { var request = wind

首先,我刚开始使用GoogleMapsAPI(并使用AJAX)。。。制造了很多问题。。。解决了这些问题。但现在我似乎被卡住了

我一直在关注Google开发者关于如何创建商店定位器()的教程——写得很好,解释得也很好——但是为了我的需要,我对它做了一些修改

现在我得到了错误

InvalidValueError:setMap:不是Map的实例,也不是实例 街景全景

创建错误的函数是:

function downloadUrl(url,callback) {
   var request = window.ActiveXObject ? 
   new ActiveXObject('Microsoft.XMLHTTP') : 
   new XMLHttpRequest;

   request.onreadystatechange = function() {
        if (request.readyState == 4) {
            request.onreadystatechange = doNothing;
            callback(request.responseText, request.status);
        }
   };

   request.open('GET', url, true);
   request.send(null); /* Console Points the Error to this line */
}
这是运行上述函数的函数:

function showAll() {
    var searchUrl = 'genxml.php';
    downloadUrl(searchUrl, function(data) {
        var xml = parseXml(data);
        var markerNodes = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markerNodes.length; i++) {
                var latlng = new google.maps.LatLng(
                    parseFloat(markerNodes[i].getAttribute("lat")),
                    parseFloat(markerNodes[i].getAttribute("lng"))
                );

        showMarker(latlng);
        }
    });
}
函数showAll(){
var searchUrl='genxml.php';
下载URL(搜索URL,函数(数据){
var xml=parseXml(数据);
var markerNodes=xml.documentElement.getElementsByTagName(“标记”);
对于(变量i=0;i
我的genxml.php工作得很好,它生成了我可以通过FireBug看到的XML文档

我仔细检查了每一行。。希望有人发现我的错误:) 如果您需要任何进一步的代码,请告诉我

编辑: -添加了初始化代码

function initialize() {
                    var hideInfos = [
                        {
                            featureType: "poi",
                            elementType: "labels",
                            stylers: [
                                { visibility: "off" }
                            ]
                    }
                ];  

                // Map configurations
                  var mapOptions = {
                    zoom:12,
                    minZoom:12,
                    maxZoom:19,
                    disableDefaultUI: true,
                    styles: hideInfos,
                    center: new google.maps.LatLng(48.149137,11.5637916)
                  };

                  // Create a new Map with the config above; save object into "map" variable
                  var map = new google.maps.Map(document.getElementById('map'),mapOptions);

                  // Borderpath configuration
                  var borderCoordinates = [
                      new google.maps.LatLng(48.096655, 11.474876),
                      new google.maps.LatLng(48.191954, 11.474876),
                      new google.maps.LatLng(48.191954, 11.655120),
                      new google.maps.LatLng(48.096655, 11.655120),
                      new google.maps.LatLng(48.096655, 11.474876)
                    ];

                    // Create a new Polyline with config above; save object into "border"
                    var border = new google.maps.Polyline({
                      path: borderCoordinates,
                      strokeColor: '#FF0000',
                      strokeOpacity: 1.0,
                      strokeWeight: 2
                    });

                    // Draw border on map
                    border.setMap(map);

                  // Create new LatLngBounds Object and save it into strictBounds
                  var strictBounds = new google.maps.LatLngBounds(
                    new google.maps.LatLng(48.096655, 11.474876), 
                    new google.maps.LatLng(48.191954, 11.655120)
                  );

                  // Listen for the dragend event and check if dragged out of strictBounds
                  google.maps.event.addListener(map, 'dragend', function() {
                    if (strictBounds.contains(map.getCenter())) return;

                    // We're out of bounds - Move the map back within the bounds
                    var c = map.getCenter(),
                        x = c.lng(),
                        y = c.lat(),
                        maxX = strictBounds.getNorthEast().lng(),
                        maxY = strictBounds.getNorthEast().lat(),
                        minX = strictBounds.getSouthWest().lng(),
                        minY = strictBounds.getSouthWest().lat();

                    if (x < minX) x = minX;
                    if (x > maxX) x = maxX;
                    if (y < minY) y = minY;
                    if (y > maxY) y = maxY;

                    map.setCenter(new google.maps.LatLng(y, x));
                  });

                  // Place Marker where clicked
                  google.maps.event.addListener(map, 'click', function(e) { 
                      placeMarker(e.latLng, map);
                  });
                }
函数初始化(){
变量hideInfos=[
{
特征类型:“poi”,
elementType:“标签”,
样式:[
{可见性:“关闭”}
]
}
];  
//地图配置
变量映射选项={
缩放:12,
minZoom:12,
maxZoom:19,
disableDefaultUI:true,
样式:HideInfo,
中心:新google.maps.LatLng(48.149137,11.5637916)
};
//使用上面的配置创建一个新映射;将对象保存到“Map”变量中
var map=new google.maps.map(document.getElementById('map'),mapOptions);
//边界路径配置
变量边界坐标=[
新的google.maps.LatLng(48.096655,11.474876),
新的google.maps.LatLng(48.191954,11.474876),
新google.maps.LatLng(48.191954,11.655120),
新的google.maps.LatLng(48.096655,11.655120),
新google.maps.LatLng(48.09665511.474876)
];
//使用上面的配置创建新的多段线;将对象保存到“边框”中
var border=new google.maps.Polyline({
路径:边界坐标,
strokeColor:“#FF0000”,
笔划不透明度:1.0,
冲程重量:2
});
//在地图上画边界
border.setMap(map);
//创建新的LatLngBounds对象并将其保存到strictBounds中
var strictBounds=new google.maps.LatLngBounds(
新的google.maps.LatLng(48.096655,11.474876),
新google.maps.LatLng(48.19195411.655120)
);
//侦听dragend事件并检查是否被拖出边界
google.maps.event.addListener(映射'dragend',函数(){
if(strictBounds.contains(map.getCenter())返回;
//我们超出边界-将地图移回边界内
var c=map.getCenter(),
x=c.lng(),
y=c.lat(),
maxX=strictBounds.getNorthEast().lng(),
maxY=strictBounds.getNorthEast().lat(),
minX=strictBounds.getSouthWest().lng(),
minY=strictBounds.getsoutwest().lat();
如果(xmaxX)x=maxX;
如果(ymaxY)y=maxY;
map.setCenter(新的google.maps.LatLng(y,x));
});
//将标记放置在单击的位置
google.maps.event.addListener(映射,'click',函数(e){
地点标记(如板条、地图);
});
}

很难看到您发布的代码有任何错误。 但我认为你所展示的是谷歌地图实例的一个错误。 请将代码粘贴到这里(地图初始化代码)

编辑:


如果我理解的话,您正在尝试调用'initialize'函数之外的'map'变量。是吗?您需要在函数外部实例化,使变量成为全局变量。

当然!编辑了主要帖子!希望有帮助!:DIf我理解了,您试图调用'initialize'函数之外的'map'变量。是吗?您需要在函数外部实例化,使变量成为全局变量。@ital0-您应该更新您的答案,现在的答案看起来就像一条注释,以包含您在随后的注释中添加的内容:-)您是最好的;非常感谢!!在initilize()函数解决映射变量之前声明它:D@duncan-等待用户响应。如果这对他有帮助,我会编辑。谢谢你的建议:)