我有一個由Lat Lng座標標識的StreetViewPanorama。 我的Lat和Lng座標並不完全位於Google汽車拍攝照片的道路上,但他們位於我想在StreetView的照片中看到的建築的中心。 所以我有兩個座標,我認爲可以計算POV度以獲得正確的建築物照片。 我需要的是如何獲得自動放置「男人」的點的Lon Lat,以便我可以計算出正確的POV度。Google Maps Api StreetView PanoramaOptions從Lon Lat的角度設置
0
A
回答
3
問題解決了:
// d is the position of the house or fisical element where I want to point the view
var d = {lat: 43.538524840485, lng: 10.322718769311};
var whereToLookLatLng = new google.maps.LatLng(parseFloat(d.lat), parseFloat(d.lng));
var panorama = new google.maps.StreetViewPanorama(
document.getElementById('pano'),
panoramaOptions
);
map.setStreetView(panorama);
var service = new google.maps.StreetViewService;
// With this function I get the panorama, if available, next the house or fisical element where I want to point the view
service.getPanoramaByLocation(panorama.getPosition(), 50,
function(panoData) {
if (panoData != null) {
// MamLatLng is the position of the point of view
var ManLatLng = panoData.location.latLng;
// Now I calculate the heading to point the view in the direction of whereToLookLatLng
var heading = google.maps.geometry.spherical.computeHeading(ManLatLng, whereToLookLatLng);
var pov = panorama.getPov();
pov.heading = heading;
panorama.setPov(pov);
}
});
}
3
我實現kiks73的解決方案。
確保在加載地圖API時添加幾何庫:
https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=visualization,places,geometry&sensor=true
var dist = 50;
service.getPanoramaByLocation(targetLatLng, dist, function(panoData){
panoramaLatLng = panoData.location.latLng;
initStreetView(targetLatLng, panoramaLatLng)
});
function initStreetView(targetLatLng, panoramaLatLng){
var panoramaOptions = {
position: targetLatLng
};
var streetView = new google.maps.StreetViewPanorama(document.getElementById('streetView'),panoramaOptions);
var heading = google.maps.geometry.spherical.computeHeading(panoramaLatLng, targetLatLng);
map.setStreetView(streetView);
streetView.setPov({heading:heading, pitch:0});
}
相關問題
- 1. 從Google Maps鏈接中查找lon/lat
- 2. StreetView上的DrawingManager? Google Maps API v3
- 3. android丟失位置對象的lon和lat的精度
- 4. Google Streetview API
- 5. Google Maps API文本搜索位置
- 6. 從facebook獲取lat和lon
- 7. Google maps API watchPosition
- 8. THREE.js - Quaternion to lat,lon
- 9. lon,lat到時區
- 10. 使用Google地圖API計算兩分之差X分鐘的位置(lat,lon)?
- 11. Google Maps API搜索
- 12. 使用Google Maps JavaScript API V3檢查StreetView的可用性
- 13. 從Google Maps API切換到Here Maps API
- 14. Google Maps API v3街景「google未定義」
- 15. 從Google Static Map獲取像素座標的lon/lat
- 16. 什麼是lon&lat的有效值
- 17. Google Maps API Rectangle
- 18. Google Maps API。投影
- 19. 使用Google Maps API V3以編程方式更新StreetView
- 20. Google Maps API - Marker Clusterer
- 21. Google Maps API設置圖標大小
- 22. 從google streetview拍照
- 23. google-maps-api-3
- 24. Grails + Google Maps API
- 25. 使用Google Maps API的Long/Lat指示的準確性
- 26. Google StreetView快照
- 27. 爲Google Maps圖像API設置寬度爲100%
- 28. Google Maps API - 放置動畫
- 29. 將Lat/Lon轉換爲MGRS
- 30. 如何從谷歌地圖api獲取地址lat和lon?
「相機」的位置是由全景爲getPosition方法返回的經緯度:https://開頭developers.google.com/maps/documentation/javascript/reference#StreetViewPanorama – geocodezip 2013-05-08 14:32:22