-1

我面临一个不寻常的问题,我需要在不知道实际位置的情况下计算具有街景图像的地图上位置的纬度。

我知道我的用户的最终目的地,但我需要计算具有街景图像的附近位置(大约 1 公里或更短,这应该是可变的)的纬度,并将其用作起始目的地。

一个例子是,我知道我需要去时代广场,但我想要一个距离公路约 1 公里的起点。然后,我需要验证该坐标是否存在街景图像,然后才能确定它是起点。

4

1 回答 1

1

下面的函数递归地将搜索距离加倍(最大为 10000 米),直到找到全景图。

示例代码:

// Global vars
var G = google.maps;
var streetViewService = new G.StreetViewService();

function getNearSVP(latlon,maxDist) {
    streetViewService.getPanoramaByLocation(latlon, maxDist, function(data, status) {
        if (status == google.maps.StreetViewStatus.OK) {
            return data.location.latLng;
        }
        else{
            if (maxDist < 10000){
                maxDist = maxDist * 2;
                return getNearSVP(latlon, maxDist);
            }
            else {
                alert('StreetView is not available within '+maxDist+' meters of this location');
            }
        }
    });

}

现场演示在这里

于 2013-01-15T08:22:08.397 回答