2012-02-08 74 views
0

目標:獲取TEXT地址,然後在同一時間顯示的街道視圖和地圖視圖如何改變街景在谷歌地圖3

參考網站:

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

我的網站: http://www.iamvishal.com/dev/property/P2154(請點擊地圖視圖查看地圖)

問題:我能夠正確顯示地圖和地址,但instreet視圖不會改變。任何想法爲什麼?

我的JS變量的地址在此情況下按住文本地址「323235巴爾莫勒爾露臺希頓泰恩河畔紐卡斯爾」

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); 
} 
} 


); 


} 

回答

0

下面是我如何創建前一個街景:

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(); 
     } 
    }); 
} 

更新:,你可以直接從現有的代碼中調用這個函數(我已經修改爲使用經緯度,而不是功能各個緯度和經度值:

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

你是如何得到intLat,intLong問題?做ü擁有該 – 2012-02-09 19:15:17

+0

代碼,你可以只使用你的「芬威」經緯度? – duncan 2012-02-10 09:06:38

+0

可惜沒因爲我需要一個文本字符串,然後獲得地理編碼geocoderTwo.geocode({「地址」:地址},功能(結果狀態) – 2012-02-10 13:26:17

0

有你的代碼一對夫婦的問題。首先解決這些問題:

64 Uncaught ReferenceError: berkeley is not defined 

此外,你需要設置你的Map之前任何一個節目和zoom選項mapTypeId

+0

在我看來就像他已經得到了變焦的mapTypeId他的MapOptions – duncan 2012-02-09 09:00:40

+0

的問題是,當頁面loads.I刪除街景視圖不更新。上的代碼,按您的 – 2012-02-09 19:13:57