0

我在 Ionic 应用程序中使用本地地理编码器。记录在这里

离子文档

Github 回购

这是我的提供者中的方法 -

//This calls the Native geocoder and returns the geocoordinates. 
  getGeoCode(address: string): Promise<any> {
    console.log('The address key is - ' + address);
    return new Promise((resolve, reject) => {
      this.nativeGeocoder.forwardGeocode(address)
        .then((nativegeocoordinates: NativeGeocoderForwardResult) => {
          console.log('The coordinates are - ' + JSON.stringify(nativegeocoordinates));
          let addressCoordinates: DeliveryAddressCoordinates = nativegeocoordinates;
          resolve(addressCoordinates);
        })
        .catch((error: any) => {
          console.log(JSON.stringify(error));
          reject(error);
        });
    })
  }

该方法接受地址字符串作为输入。所以我从 google places API 获取地址,并在此处传递描述。

现在,对于某些地址,它似乎找不到坐标,并返回“找不到位置”消息。例如,“Bhadra Brookefields Apartment B Block, Kundanahalli Lake Road, Kundalahalli, Brookefield, Bengaluru, Karnataka, India”是一个有效地址并返回坐标,而“Times Square 42 Street Station, New York, NY, USA”没有找到匹配并返回一条消息 - “找不到位置”。

有关更多信息,“找不到位置”似乎源自第 182 行的 cordova 插件代码。,它在哪里引用 Android 类。

这是一个已知的问题?还是我做错了什么?

4

2 回答 2

1

至少还有一个人认为该插件似乎有点受欢迎 - 请在下面对这篇文章发表评论

Ionic 2 – Geolocation and GeocodingIonic 2 – Geolocation and Geocoding

评论来自紫边先生,我无法链接评论本身,因为它是一个 disq,并且 Stack 不允许。

因此,我求助于可以解释为解决方案或解决方法的方法。我没有使用插件,而是简单地使用 api,从而发出 Http 请求来获取信息。

获取信息的方法(在提供程序中):

 getGeoCodefromGoogleAPI(address: string): Observable<any> {
    return this._http.get('https://maps.googleapis.com/maps/api/geocode/json?address=' + address)
      .map(res => res.json());
  }

方法调用->

this._deliveryAddressService.getGeoCodefromGoogleAPI(event.description).subscribe(addressData => {

        let latitude: string = addressData.results[0].geometry.location.lat;
        let longitude: string = addressData.results[0].geometry.location.lng;
        }

当然,需要有注册密钥的正当程序。

于 2018-03-16T20:04:45.050 回答
0

不是插件的问题。您只需添加更多,以便您可以请求High Accuracy在手机中激活的权限。

https://ionicframework.com/docs/native/location-accuracy/

于 2018-08-09T06:46:48.307 回答