0

我在用leaflet-geosearch用来搜索我在谷歌地图页面中显示的地址的经度和纬度,我正在使用角度

在我的组件中

private openAddressInMap() {
    this.provider.search({query: address}).then(result => { // search coordinates for each city
      if (!isNullOrUndefined(result) && result.length > 0 && !isNullOrUndefined(result[0])) {
        const lng = result[0].x;
        const lat = result[0].y;
        window.open('https://maps.google.com/?q=' + lat + ',' + lng, '_blank');
      }
    });
}

然后我通过传递 lat 和 lng 打开谷歌地图链接,问题是标记没有很好定位,它指向错误的地址

4

1 回答 1

0

你真的需要通过地理编码器获取坐标吗?如果您使用Google Maps URLs,您可以直接将地址作为queryURL 的参数发送,避免地理编码请求

代码片段是

private openAddressInMap() {
    window.open('https://www.google.com/maps/search/?api=1&query=' + encodeURIComponent(address), '_blank');
}

例如,尝试以下 URL:

https://www.google.com/maps/search/?api=1&query=New+York

我希望这有帮助!

于 2019-07-23T22:42:23.500 回答