【问题标题】:How to get the coordinates of the point where we dropped the pegman in Google maps如何获取我们在谷歌地图中丢下街景小人的点的坐标
【发布时间】:2012-11-14 12:57:12
【问题描述】:

我在这里有一个演示 http://jsfiddle.net/coderslay/vQVTq/

js如下所示

function initialize() {
    var fenway = new google.maps.LatLng(42.345573,-71.098326);
    var panoramaOptions = {
        enableCloseButton : true,
        visible: false
    };
    var panorama = new  google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
    var mapOptions = {
      center: fenway,
      zoom: 14,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      streetView : panorama
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);


    google.maps.event.addListener(panorama, "visible_changed", function() {
        if (panorama.getVisible() && $("#pano").is(':visible')){
            //moving the pegman around the map
        }else if(panorama.getVisible() && $("#pano").is(':hidden')){
            $("#pano").show();
            $("#map_canvas").removeClass('bigmap');
            $("#map_canvas").addClass('minimap');
        }
        google.maps.event.addListener(panorama, "closeclick", function() {
            $("#pano").hide();  
            $("#map_canvas").removeClass('minimap');
            $("#map_canvas").addClass('bigmap');         
        });
    });

css在这里

#container {
width:500px;
height: 500px ;
position: relative;
}

#map_canvas, 
#pano {
    position: absolute;
    top: 0;
    left: 0;
}

#map_canvas {
    z-index: 10;
}

.bigmap{
    width:100%;
    height:100%;
}

.minimap{
    width:50%;
    height:100%;
}​  

当我将街景小人拖到地图上的任意一点时,地图就会分成两部分。一个是普通视图,另一个是街景。现在我想在法线贴图上显示街景小人被丢弃的位置。如何获取该特定点的坐标。这样我就可以平移到那个位置。怎么做?

【问题讨论】:

  • 感谢您的问题和代码。我有点受启发。仅供参考:将小地图更改为大地图(反之亦然)时,您应该使用google.maps.event.trigger(map, "resize"); 以便地图重新启动其中心。

标签: javascript jquery google-maps google-street-view


【解决方案1】:

我认为您可以在 StreetViewPanorama 类中使用 getPosition() 方法。

google.maps.event.addListener(panorama, "visible_changed", function() {
  map.setCenter(panorama.getPosition());
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多