首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改谷歌地图3中的街道视图

如何更改谷歌地图3中的街道视图
EN

Stack Overflow用户
提问于 2012-02-08 20:14:15
回答 2查看 5.9K关注 0票数 0

目标:获取文本地址,然后同时显示街道视图和地图视图

参考网站:

http://code.google.com/apis/maps/documentation/javascript/examples/streetview-simple.html

我的网站:http://www.iamvishal.com/dev/property/P2154 (请点击地图视图查看地图)

问题:我能够正确地显示地图和地址,但是instreet视图不会改变。知道为什么吗?

我的js变量地址持有文本地址--在本例中为"323235 Balmoral Terrace Tyne“

代码语言:javascript
复制
function initialize() 
{
var fenway = new google.maps.LatLng(42.345573,-71.098326);
var mapOptions = {
    center: fenway,
    zoom: 14,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(
document.getElementById("map_canvas"), mapOptions);

var panoramaOptions = {
    position: fenway,
    pov: {
         heading: 34,
         pitch: 10,
         zoom: 1
         }
   };

var panorama = new  google.maps.StreetViewPanorama(document.getElementById("pano"), 
panoramaOptions);

map.setStreetView(panorama);

var geocoderTwo = new google.maps.Geocoder();

geocoderTwo.geocode({"address":address},function(results, status)
{
   if (status == google.maps.GeocoderStatus.OK) 
   {
      map.setCenter(results[0].geometry.location);
      var marker = new google.maps.Marker
      ({
        map: map,
        position: results[0].geometry.location
      });
   }
else
{
  alert("Geocode was not successful for the following reason: " + status);
}
}


);


}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-09 09:07:32

下面是我以前创建街景的方法:

代码语言:javascript
复制
function createStreetMap(strMapCanvasID, yourLatLng)
{
    var panorama;

    //once the document is loaded, see if google has a streetview image within 50 meters of the given location, and load that panorama
    var sv = new google.maps.StreetViewService();

    sv.getPanoramaByLocation(yourLatLng, 50, function(data, status) {
        if (status == 'OK') {
            //google has a streetview image for this location, so attach it to the streetview div
            var panoramaOptions = {
                pano: data.location.pano,
                addressControl: false,
                navigationControl: true,
                navigationControlOptions: {
                    style: google.maps.NavigationControlStyle.SMALL
                }
            }; 
            var panorama = new google.maps.StreetViewPanorama(document.getElementById(strMapCanvasID), panoramaOptions);


            // lets try and hide the pegman control from the normal map, if we're displaying a seperate streetview map
            objCreatedMap.setOptions({
                streetViewControl: false
            });
        }
        else{
            //no google streetview image for this location, so hide the streetview div
            $('#' + strMapCanvasID).parent().hide();
        }
    });
}

更新:和您可以在现有代码中直接调用该函数(我已经修改了该函数以使用LatLng,而不是单个纬度和经度值):

代码语言:javascript
复制
if (status == google.maps.GeocoderStatus.OK) 
   {
      map.setCenter(results[0].geometry.location);
      var marker = new google.maps.Marker
      ({
        map: map,
        position: results[0].geometry.location
      });

      createStreetMap('yourStreetViewDiv', results[0].geometry.location);
   }
票数 0
EN

Stack Overflow用户

发布于 2012-02-08 21:31:55

您的代码有几个问题。首先修复它们:

代码语言:javascript
复制
64 Uncaught ReferenceError: berkeley is not defined

此外,在显示任何内容之前,您还需要在zoommapTypeId选项上设置Map

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9200692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档