实施 Google 地图 v3 街景
我想弄清楚如何将以下三张地图之一变成街景。
- 路线图
- 混合
- 卫星
这是下面的代码,我用它来生成三个不同的谷歌地图:
var map;
var map2;
var map3;
$(document).ready(function(){
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
var myLatLng = new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
var myOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map-canvas-1"),myOptions);
var myOptions2 = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.HYBRID
}
map2 = new google.maps.Map(document.getElementById("map-canvas-2"),myOptions2);
var myOptions3 = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.SATELLITE
}
map3 = new google.maps.Map(document.getElementById("map-canvas-3"),myOptions3);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title:"Map1" });
var marker = new google.maps.Marker({
position: myLatLng,
map: map2,
title:"Map2" });
var marker = new google.maps.Marker({
position: myLatLng,
map: map3,
title:"Map3" });
}
这是地图划分的代码:
<div id="maptabs">
<ul>
<li><a href="#maptabs-1">Road Map</a></li>
<li><a href="#maptabs-2">Hybrid</a></li>
<li><a href="#maptabs-3">Satellite</a></li>
</ul>
<div id="maptabs-1">
<div id="map-canvas-1" class="map"></div>
</div>
<div id="maptabs-2">
<div id="map-canvas-2" class="map"></div>
</div>
<div id="maptabs-3">
<div id="map-canvas-3" class="map"></div>
</div>
</div>
如何更改卫星地图的地图选项以将其转换为街景视图?谢谢。
I am trying to figure out how to turn one of the following three maps into a street view.
- Road Map
- Hybrid
- Satellite
This is the code below that I use to generate three different google maps:
var map;
var map2;
var map3;
$(document).ready(function(){
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
var myLatLng = new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
var myOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map-canvas-1"),myOptions);
var myOptions2 = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.HYBRID
}
map2 = new google.maps.Map(document.getElementById("map-canvas-2"),myOptions2);
var myOptions3 = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.SATELLITE
}
map3 = new google.maps.Map(document.getElementById("map-canvas-3"),myOptions3);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title:"Map1" });
var marker = new google.maps.Marker({
position: myLatLng,
map: map2,
title:"Map2" });
var marker = new google.maps.Marker({
position: myLatLng,
map: map3,
title:"Map3" });
}
Here is the code for the map division:
<div id="maptabs">
<ul>
<li><a href="#maptabs-1">Road Map</a></li>
<li><a href="#maptabs-2">Hybrid</a></li>
<li><a href="#maptabs-3">Satellite</a></li>
</ul>
<div id="maptabs-1">
<div id="map-canvas-1" class="map"></div>
</div>
<div id="maptabs-2">
<div id="map-canvas-2" class="map"></div>
</div>
<div id="maptabs-3">
<div id="map-canvas-3" class="map"></div>
</div>
</div>
How do I alter the map options for the satellite map to turn it into a street view instead? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法通过更改 MapOptions 来完成此操作,因为街景视图不是 MapType。最简单的事情可能是以编程方式指示地图显示其 StreetViewPanorama,如下所示:
You can't do it by altering the MapOptions because a street view is not a MapType. The easiest thing to do is probably to programmatically instruct the map to show its StreetViewPanorama like so:
这并不像 Trott 的答案那么简单,因为 POV 会是错误的。我刚刚花了几个小时在这个问题上,这是我的答案,对于那些最终提出这个问题的人(因为这是我发现的问题之一,但答案没有用)。
默认情况下,街景 POV 是拍摄图像时卡车所面向的方向(见图)。您需要获取卡车的位置和房屋的位置,并计算从第一个位置到第二个位置的“航向”,然后将您的街景位置设置为具有刚刚计算的航向的卡车的位置:
使用街景视图的另一个技巧/陷阱是,您需要通过不断增加距离重复调用
getPanoramaByLocation
来获取距离您的地址位置最近的街景视图,直到成功或达到某个最大值距离。我使用这段代码解决了这个问题:It's not as simple as Trott's answer because the POV will be wrong. I just spent several hours on this, and here's my answer, for those who end up on this question (since this is one of the questions I found, but the answer was of no use).
The street view POV is, by default, the direction the truck was facing when the image was shot (go figure). You need to get the location of the truck and the location of the house and calculate a "heading" from the first location to the second, then set your street-view location to that of the truck with the heading you just calculated:
Another trick/trap using street view is that you need to obtain the closest street view to your address location by repeatedly calling
getPanoramaByLocation
with an increasing distance until you are either successful or reach some maximum distance. I solve this using this code: