2015-11-06 68 views
9

所以在我的網站我使用谷歌地圖+街景: https://developers.google.com/maps/documentation/javascript/examples/streetview-simple谷歌地圖+街景的問題 - 如何禁用的Photo Sphere

而且我使用搜索框標準與自動完成,問題是,當我輸入一些地點,沒有街景,只是Photo Sphere圖像沒有任何控制,像在標準的街景視圖中移動...

我真的不想要Photo Sphere,因爲我希望我的用戶可以隨意移動街景,現在他們有時會被困在一個Photo Sphere照片中......有沒有辦法讓我的照片在沒有Photo Sphere的情況下強制進行街景?

+0

全景不是在同一個地方的地圖的中心。全景圖的位置在哪裏? –

+0

我看到您的網站已更新。它現在有效,對嗎?沒有更多的問題? –

+0

不幸的是,我沒有找到解決辦法,只是現在可以接受的某種修改。 Wen用戶從自動填充中選擇一個地址,在很多情況下我沒有在城市中顯示街景,這激活Photo Sphere,位置相同+/-少量,然後在大多數情況下顯示街景而不是照片領域。對我來說,它的redicolous Google劑量可以選擇簡單地將其關閉... – Dreadlord

回答

3

我不確定如何關閉PhotoSpheres,但我確實找到了可能對您有用的解決方法。我在https://developers.google.com/maps/documentation/javascript/reference#StreetViewSource注意到,當搜索一個位置時,如果您將源設置爲OUTDOOR,則不會返回PhotoSpheres。

因此,如果您爲位置更改添加偵聽器,然後在沒有PhotoSpheres的情況下搜索位置,我認爲您應該能夠防止它們出現。

這裏是修飾的谷歌地圖的例子來說明:

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title>Place Autocomplete without PhotoSpheres</title> 
 
\t <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
 
\t <meta charset="utf-8"> 
 
\t <style> 
 
\t \t html, body { 
 
\t \t \t height: 100%; 
 
\t \t \t margin: 0; 
 
\t \t \t padding: 0; 
 
\t \t } 
 
\t \t #map, #pano { 
 
\t \t \t height: 100%; 
 
\t \t \t width: 50%; 
 
\t \t \t float:left; 
 
\t \t } 
 
\t \t .controls { 
 
\t \t \t margin-top: 10px; 
 
\t \t \t border: 1px solid transparent; 
 
\t \t \t border-radius: 2px 0 0 2px; 
 
\t \t \t box-sizing: border-box; 
 
\t \t \t -moz-box-sizing: border-box; 
 
\t \t \t height: 32px; 
 
\t \t \t outline: none; 
 
\t \t \t box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); 
 
\t \t } 
 

 
\t \t #pac-input { 
 
\t \t \t background-color: #fff; 
 
\t \t \t font-family: Roboto; 
 
\t \t \t font-size: 15px; 
 
\t \t \t font-weight: 300; 
 
\t \t \t margin-left: 12px; 
 
\t \t \t padding: 0 11px 0 13px; 
 
\t \t \t text-overflow: ellipsis; 
 
\t \t \t width: 300px; 
 
\t \t } 
 

 
\t \t #pac-input:focus { 
 
\t \t \t border-color: #4d90fe; 
 
\t \t } 
 

 
\t \t .pac-container { 
 
\t \t \t font-family: Roboto; 
 
\t \t } 
 

 
\t \t #type-selector { 
 
\t \t \t color: #fff; 
 
\t \t \t background-color: #4d90fe; 
 
\t \t \t padding: 5px 11px 0px 11px; 
 
\t \t } 
 

 
\t \t #type-selector label { 
 
\t \t \t font-family: Roboto; 
 
\t \t \t font-size: 13px; 
 
\t \t \t font-weight: 300; 
 
\t \t } 
 

 
\t </style> 
 
</head> 
 
<body> 
 
<input id="pac-input" class="controls" type="text" 
 
     placeholder="Enter a location"> 
 
<div id="map"></div> 
 
<div id="pano"></div> 
 
<script> 
 

 
\t var map; 
 
\t var panorama; 
 
\t var streetViewService; 
 
\t var DEFAULT_PROXIMITY = 50; 
 
\t var MAX_PROXIMITY = 10000; 
 

 
\t function initMap() { 
 
\t \t map = new google.maps.Map(document.getElementById('map'), { 
 
\t \t \t center: {lat: -33.8688, lng: 151.2195}, 
 
\t \t \t zoom: 13 
 
\t \t }); 
 
\t \t var input = /** @type {!HTMLInputElement} */(
 
\t \t \t document.getElementById('pac-input')); 
 

 
\t \t map.controls[google.maps.ControlPosition.TOP_LEFT].push(input); 
 

 
\t \t var autocomplete = new google.maps.places.Autocomplete(input); 
 
\t \t //autocomplete.bindTo('bounds', map); 
 

 
\t \t streetViewService = new google.maps.StreetViewService(); 
 
\t \t panorama = new google.maps.StreetViewPanorama(
 
\t \t \t document.getElementById('pano'), { 
 
\t \t \t \t position: {lat: -33.8688, lng: 151.2195}, 
 
\t \t \t \t pov: { 
 
\t \t \t \t \t heading: 34, 
 
\t \t \t \t \t pitch: 10 
 
\t \t \t \t } 
 
\t \t \t }); 
 
\t \t map.setStreetView(panorama); 
 

 
\t \t autocomplete.addListener('place_changed', function() { 
 
\t \t \t var place = autocomplete.getPlace(); 
 
\t \t \t if (!place.geometry) { 
 
\t \t \t \t window.alert("Autocomplete's returned place contains no geometry"); 
 
\t \t \t \t return; 
 
\t \t \t } 
 
\t \t \t // If the place has a geometry, then present it on a map. 
 
\t \t \t if (place.geometry.location) { 
 
\t \t \t \t findClosestStreetView(place.geometry.location, DEFAULT_PROXIMITY); 
 
\t \t \t } 
 
\t \t }); 
 

 
\t \t function findClosestStreetView(point, proximity) { 
 
\t \t \t streetViewService.getPanorama({location: point, radius: proximity, source: google.maps.StreetViewSource.OUTDOOR}, function processSVData(data, status) { 
 
\t \t \t \t if (status == google.maps.StreetViewStatus.OK) { 
 
\t \t \t \t \t map.panTo(data.location.latLng); 
 
\t \t \t \t \t panorama.setPano(data.location.pano); 
 
\t \t \t \t } else { 
 
\t \t \t \t \t if (proximity < MAX_PROXIMITY) { 
 
\t \t \t \t \t \t findClosestStreetView(point, proximity + 50); 
 
\t \t \t \t \t } else { 
 
\t \t \t \t \t \t // NO PANARAMA FOUND - do something else here... 
 
\t \t \t \t \t \t panorama.setVisible(false); 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t }); 
 
\t \t } 
 

 
\t } 
 

 
</script> 
 
<script src="https://maps.googleapis.com/maps/api/js?&libraries=places&callback=initMap" async defer></script> 
 
</body> 
 
</html>