如何检测地址/坐标中是否有Google StreetView

时间:2012-11-05 16:33:21

标签: google-api google-street-view

我正在制作一款使用Google街景图片API的应用

根据地址/坐标

获取街景图像没有问题

但是 - 我想检测特定地址是否有可用的街景图像(为了显示没有它的地址的不同行为)

我到目前为止唯一的想法是读取返回图像的像素并检测这是否是没有图像时我得到的图像

还有其他想法吗?

谢谢!

3 个答案:

答案 0 :(得分:6)

使用google.maps.StreetViewService.getPanoramaByLocation(latlng,radius,callback()),您可以检查是否有街景全景图。 如果有街景全景图,则必须有街景图像。

你可以参考谷歌的参考: https://developers.google.com/maps/documentation/javascript/reference#StreetViewService

或者参考StreetViewService的示例: https://google-developers.appspot.com/maps/documentation/javascript/examples/streetview-service

答案 1 :(得分:1)

  mStreetViewPanorama.setOnStreetViewPanoramaChangeListener(streetViewPanoramaLocation -> {
                if (streetViewPanoramaLocation != null && streetViewPanoramaLocation.links != null) {
                    Toast.makeText(StreetViewActivity.this, "StreetView Camera Found", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(StreetViewActivity.this, "StreetView Camera not Found", Toast.LENGTH_SHORT).show();
                }
            });

答案 2 :(得分:0)

Google有一个api端点,您可以在其中查找全景图/街景图的元数据:

https://maps.googleapis.com/maps/api/streetview/metadata?key=YOUR_API_KEY&location=STRING_ADDRESS_OR_LAT_LNG_COORDINATES

您可以检查响应的status属性。

成功的反应

{
   "copyright" : "© 2017 Google",
   "date" : "2016-05",
   "location" : {
      "lat" : 48.85783227207914,
      "lng" : 2.295226175151347
   },
   "pano_id" : "tu510ie_z4ptBZYo2BGEJg",
   "status" : "OK"
}

响应失败

{
   "status" : "ZERO_RESULTS"
}

@请参阅https://developers.google.com/maps/documentation/streetview/metadata