Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何重定向到谷歌地图?_Javascript - Fatal编程技术网

Javascript 如何重定向到谷歌地图?

Javascript 如何重定向到谷歌地图?,javascript,Javascript,我有以下代码在我的测试网页中显示地图 <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs

我有以下代码在我的测试网页中显示地图

<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAvY_htg5RzYE1oj2BL4bFvxSRc9RmgUY0ng1PT46gfsZ_uuISzxROX5ZCo6sw1juxfGN03mgyAPAIoA" type="text/javascript"></script>

   <script type="text/javascript">

    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(xxx,xxx), 13);

        var marker = new GMarker(map.getCenter());
        GEvent.addListener(marker, "click", function () {
          marker.openInfoWindowHtml("xxxxxxxxxxxx");
        });
        map.addOverlay(marker);
      }
    }

    </script>
    </head>
    <body  onLoad="initialize()">
        <div id="map_canvas" style="width: 300px; height: 250px; margin:auto;"></div> 
    </body>
</html>

函数初始化(){
if(GBrowserIsCompatible()){
var map=newgmap2(document.getElementById(“map_canvas”);
地图设置中心(新格拉特林(xxx,xxx),13);
var marker=newgmarker(map.getCenter());
addListener(标记“单击”,函数(){
marker.openInfoWindowHtml(“xxxxxxxxxx”);
});
添加覆盖图(标记);
}
}

我想重定向到谷歌地图网站与确切的地址位置,我用来显示在地图上的位置,如果我点击地图位置。希望你们理解我的要求。有可能吗?

您可以尝试以下方法

function returnMapUrl(GLatLngObj){
     var point= GLatLngObj || map.getCenter();
     return "http://maps.google.com/?ll="+point.lat+','+point.lng;
} 

GEvent.addListener(map,"click", function(overlay, latlng) {
    window.location = returnMapUrl(latlng);
});

谢谢,现在更新我的帖子…当我点击我的地图位置时,我需要重定向。好吧,你必须将我的代码集成到你的`if(GBrowserIsCompatible()){}`代码块中。我把那段代码放在那块代码块中,把函数returnMapUrl放在那块代码块之外……我再次得到了未定义的警报(GLatLngObj)