简体   繁体   English

Google Maps API V3-同一地图上有标记的两个位置

[英]Google maps API V3 - Two location with markers on same map

I want to display two different location on map at same time, one is current location and other one is different location. 我想同时在地图上显示两个不同的位置,一个是当前位置,另一个是不同的位置。 I use javascript V3 version. 我使用的是javascript V3版本。 This is my code for display one location. 这是我显示一个位置的代码。

         var pos = new google.maps.LatLng(latitude, longitude);


             window.localStorage.setItem("event_location",pos);

             if (!google) {
                    loadScript();
                }
             var pos1 = window.localStorage.getItem("current_location");
                alert('position '+pos1);

                var myOptions = {
                    center : pos,
                    zoom : 8,
                    mapTypeId : google.maps.MapTypeId.ROADMAP
                };


                var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

                var contentString = '<div id="content">'+
                '<div id="siteNotice">'+
                '</div>'+
                '<h4 id="firstHeading" class="firstHeading">'+add+'</h4> ' +
                '<div id="bodyContent">'+
                '<p>Meeting with'+'<b> '+ personName + '</b>, <br/>on ' +
                '<b>'+startDate+'</b> at ' + 
                '<b>'+startTime+'</b>' + 
                '</div>'+
                '</div>';


            var infowindow = new google.maps.InfoWindow({
                content: contentString
            });

            var marker = new google.maps.Marker({
                position: pos,
                map: map,
                title:"Event Location!"
            });



            google.maps.event.addListener(marker, 'click', function() {
              infowindow.open(map,marker);
            });

pos1 is my second location which is calculated by phonegap current location method. pos1是我的第二个位置,它是通过phonegap当前位置方法计算得出的。 Please help me out. 请帮帮我。

If pos1 is google.maps.LatLng instance 如果pos1google.maps.LatLng实例

var marker = new google.maps.Marker({
    position: pos,
    map: map,
    title:"Event Location!"
});

google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
});

var marker1 = new google.maps.Marker({
    position: pos1,
    map: map,
    title:"New Location!"
});

google.maps.event.addListener(marker1, 'click', function() {
    infowindow.open(map,marker1);
});

marker.setMap(map);
marker1.setMap(map);

write the code for displaying the second marker ie if u have the lat long for pos1 create a marker and display it on the same map. 编写用于显示第二个标记的代码,即,如果您的pos1的纬度长,则创建一个标记并将其显示在同一地图上。 it will hardly take milliseconds to display the secod marker if the client browser has got reasonable processing capacity 如果客户端浏览器具有合理的处理能力,则几乎无需花费毫秒来显示秒标记

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

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