Zak*_*Zak 7 google-maps google-maps-api-3 google-maps-markers google-street-view
我有一个简单的街景工作,给我一个给出地址的街景:
var geocoder = new google.maps.Geocoder();
var address = "344 Laguna Dr, Milpitas, CA 95035";
geocoder.geocode( { 'address': address},
function(results, status) {
//alert (results);
if (status == google.maps.GeocoderStatus.OK) {
//alert(results[0].geometry.location);
myStreetView = new google.maps.StreetViewPanorama(document.getElementById("map_canvas"));
myStreetView.setPosition(results[0].geometry.location);
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: myStreetView,
title:address
});
//alert ("yay");
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
Run Code Online (Sandbox Code Playgroud)
如您所见,我在街景视图中添加了地址标记.我的问题是,街景指向北方,标记位于南方.对于非特定地址,如何指定街景视图应指向地址的标记而不是默认指向北?
查看此示例。即使它是 V2,您也可以重用该代码。基本上,您需要调用computeAngle(markerLatLng, streetviewPanoLatLng),并将街景全景的偏航设置为返回值。
function computeAngle(endLatLng, startLatLng) {
var DEGREE_PER_RADIAN = 57.2957795;
var RADIAN_PER_DEGREE = 0.017453;
var dlat = endLatLng.lat() - startLatLng.lat();
var dlng = endLatLng.lng() - startLatLng.lng();
// We multiply dlng with cos(endLat), since the two points are very closeby,
// so we assume their cos values are approximately equal.
var yaw = Math.atan2(dlng * Math.cos(endLatLng.lat() * RADIAN_PER_DEGREE), dlat)
* DEGREE_PER_RADIAN;
return wrapAngle(yaw);
}
function wrapAngle(angle) {
if (angle >= 360) {
angle -= 360;
} else if (angle < 0) {
angle += 360;
}
return angle;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8621 次 |
| 最近记录: |