从Google街景中获取lat / lng / zoom / yaw / pitch

时间:2022-11-02 21:18:35

I have a Google map and street view based on provided lat/lng coordinates, zoom, yaw and pitch. I need to invoke a javascript to update a hidden field for each of these values whenever any of the details change from their default or when a button is clicked.

我有基于提供的lat / lng坐标,缩放,偏航和俯仰的Google地图和街景视图。每当任何细节从默认值或单击按钮更改时,我都需要调用javascript来更新每个值的隐藏字段。

So whenever the map/street view is zoomed in, panned, tilted etc it outputs the new details.

因此,无论何时地图/街道视图被放大,平移,倾斜等,它都会输出新的细节。

How do I call the functions getPOV(), yawchanged(yaw:Number), pitchchanged(pitch:Number), and zoomchanged(zoom:Number) whenever the Street View is changed (similar to moveend for Maps)

每当街景视图发生变化时,如何调用函数getPOV(),yawchanged(yaw:Number),pitchchanged(pitch:Number)和zoomchanged(zoom:Number)(类似于地图的moveend)

3 个解决方案

#1


Not sure of the best way to compress this but this works to get the changed details:

不确定压缩这个的最佳方法,但这可以获得更改的细节:

GEvent.addListener(myPano, 'initialized', function(pano) {
  alert("newlng: " + pano.latlng.lng() + ", newlat: " + pano.latlng.lat());
});

GEvent.addListener(myPano, 'yawchanged', function(newyaw){
  alert("yawchanged: " + newyaw);
});

GEvent.addListener(myPano, 'pitchchanged', function(newpitch) {
  alert("pitchchanged: " + newpitch);
});

GEvent.addListener(myPano, 'zoomchanged', function(newzoom) {
  alert("zoomchanged: " + newzoom);
});

#2


I generally have found that "moveend" is the best event to use as a hook to get the state of the map when a user changes it. I will need to look up how to get the lat/lng, zoom, yaw, and pitch from the map isntanct when I have more time this afternoon

我通常发现“moveend”是用作钩子的最佳事件,用于在用户更改时获取地图的状态。今天下午我有更多时间,我需要查看如何从地图中获取lat / lng,zoom,yaw和pitch。

// map is the instance of your GMap2
GEvent.addListener(map, 'moveend', function() {
  var center = map.getCenter();
  var zoom = map.getZoom();

  alert([center.lat(), center.lng(), zoom].join(','));
});

#3


For google maps api v3... Assuming you have a streetView map already loaded named "panorama"

对于google maps api v3 ...假设你已经加载了一个名为“panorama”的streetView地图

google.maps.event.addListener(panorama, "pov_changed", function() { 
   var panoInfo   = panorama.getPov();
   var thePitch   = panoInfo['pitch'];
   var isHeading  = panoInfo['heading'];
   var theZoom    = panoInfo['zoom'];
});

#1


Not sure of the best way to compress this but this works to get the changed details:

不确定压缩这个的最佳方法,但这可以获得更改的细节:

GEvent.addListener(myPano, 'initialized', function(pano) {
  alert("newlng: " + pano.latlng.lng() + ", newlat: " + pano.latlng.lat());
});

GEvent.addListener(myPano, 'yawchanged', function(newyaw){
  alert("yawchanged: " + newyaw);
});

GEvent.addListener(myPano, 'pitchchanged', function(newpitch) {
  alert("pitchchanged: " + newpitch);
});

GEvent.addListener(myPano, 'zoomchanged', function(newzoom) {
  alert("zoomchanged: " + newzoom);
});

#2


I generally have found that "moveend" is the best event to use as a hook to get the state of the map when a user changes it. I will need to look up how to get the lat/lng, zoom, yaw, and pitch from the map isntanct when I have more time this afternoon

我通常发现“moveend”是用作钩子的最佳事件,用于在用户更改时获取地图的状态。今天下午我有更多时间,我需要查看如何从地图中获取lat / lng,zoom,yaw和pitch。

// map is the instance of your GMap2
GEvent.addListener(map, 'moveend', function() {
  var center = map.getCenter();
  var zoom = map.getZoom();

  alert([center.lat(), center.lng(), zoom].join(','));
});

#3


For google maps api v3... Assuming you have a streetView map already loaded named "panorama"

对于google maps api v3 ...假设你已经加载了一个名为“panorama”的streetView地图

google.maps.event.addListener(panorama, "pov_changed", function() { 
   var panoInfo   = panorama.getPov();
   var thePitch   = panoInfo['pitch'];
   var isHeading  = panoInfo['heading'];
   var theZoom    = panoInfo['zoom'];
});