简体   繁体   English

点击谷歌地图在新窗口中打开链接

[英]Click on the google map to open a link in a new window

I used the code from a website as shown below to let me show a google map in my page. 我使用了如下所示的网站代码,以便在页面中显示Google地图。 You can see it in action here http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/12/google-maps-simple-example.html 您可以在这里http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/12/google-maps-simple-example.html看到它的运行情况

My question is how can i change the code to when a user clicks on the map to open a link in a new window? 我的问题是当用户单击地图以在新窗口中打开链接时,如何将代码更改为?

Thank you 谢谢

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>  
<script type="text/javascript">
    $(document).ready(function () {
        // Define the latitude and longitude positions
        var latitude = parseFloat("38.1447817");
        var longitude = parseFloat("23.848843");
        var latlngPos = new google.maps.LatLng(latitude, longitude);
        // Set up options for the Google map
        var myOptions = {
            zoom: 15,
            center: latlngPos,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        // Define the map
        map = new google.maps.Map(document.getElementById("map"), myOptions);
        // Add the marker
        var marker = new google.maps.Marker({
            position: latlngPos,
            map: map,
            title: "Auto Marin"
        });
    });
</script>


<div id="map" style="width:230px;height:140px;"></div>

You could add an event listener. 您可以添加事件监听器。

google.maps.event.addListener(map, "click", function(){
     window.open(*LINK*)
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM