我如何知道谷歌街景图片的位置?

时间:2016-06-14 04:35:35

标签: google-maps

我想知道特定位置周围的谷歌街景图像的位置(纬度和经度)。我该怎么办 ? (谷歌地图api,javascript,URL)

2 个答案:

答案 0 :(得分:0)

Check this link out for geo location
应该向您发送正确的方向。它适用于人员IP地址,因此如果他们的IP被屏蔽或重新路由,您将无法获得准确的经度和纬度,而是其ISP的位置

答案 1 :(得分:0)

来自the documentation(强调我的):

  

直接访问街景数据

     

您可能希望以编程方式确定街景数据的可用性,或返回有关特定全景图的信息,而无需直接操纵地图/全景图。您可以使用StreetViewService对象执行此操作,该对象为存储在Google街景服务中的数据提供界面。

     

您可以向StreetViewService发起两种类型的请求:

     

<snip>

     
      
  • 使用StreetViewLocationRequest请求在给定传递的LatLng的情况下搜索给定区域的全景数据。
  •   

代码段(从this example in the documentation复制,点击地图返回最近的街景全景图)

&#13;
&#13;
/* 
 * Click the map to set a new location for the Street View camera.
 */
var map;
var panorama;

function initMap() {
  var berkeley = {
    lat: 37.869085,
    lng: -122.254775
  };
  var sv = new google.maps.StreetViewService();
  panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'));
  // Set up the map.
  map = new google.maps.Map(document.getElementById('map'), {
    center: berkeley,
    zoom: 16,
    streetViewControl: false
  });
  // Set the initial Street View camera to the center of the map
  sv.getPanorama({
    location: berkeley,
    radius: 50
  }, processSVData);
  // Look for a nearby Street View panorama when the map is clicked. 
  // getPanoramaByLocation will return the nearest pano when the 
  // given radius is 50 meters or less.
  map.addListener('click', function(event) {
    sv.getPanorama({
      location: event.latLng,
      radius: 50
    }, processSVData);
  });
}

function processSVData(data, status) {
  if (status === google.maps.StreetViewStatus.OK) {
    var marker = new google.maps.Marker({
      position: data.location.latLng,
      map: map,
      title: data.location.description
    });
    panorama.setPano(data.location.pano);
    panorama.setPov({
      heading: 270,
      pitch: 0
    });
    panorama.setVisible(true);
    marker.addListener('click', function() {
      var markerPanoID = data.location.pano;
      // Set the Pano to use the passed panoID.
      panorama.setPano(markerPanoID);
      panorama.setPov({
        heading: 270,
        pitch: 0
      });
      panorama.setVisible(true);
    });
  } else {
    console.error('Street View data not found for this location.');
  }
}
&#13;
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
#map {
  height: 100%;
}
&#13;
<div id="map" style="width: 45%; height: 100%;float:left"></div>
<div id="pano" style="width: 45%; height: 100%;float:left"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?callback=initMap"></script>
&#13;
&#13;
&#13;