开发者

How to redirect to Google Map?

开发者 https://www.devze.com 2023-03-26 14:22 出处:网络
I have the following piece of code to display map in my test web page <ht开发者_StackOverflow中文版ml>

I have the following piece of code to display map in my test web page

<ht开发者_StackOverflow中文版ml>
    <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>

I want to redirect to GOOGLE MAP site with exact address location which i used to display Location in Map IF I CLICK ON MAP LOCATION.Hope you understand my requirement. Is it possible?


you could try something like

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);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号