【问题标题】:Ionic Native Geocoder "Cannot find a location."离子原生地理编码器“找不到位置。”
【发布时间】:2018-08-25 17:07:03
【问题描述】:

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

Ionic documentation

Github Repo

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

//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” 未找到匹配项并返回一条消息 - “找不到位置”。

有关更多信息,“找不到位置”似乎来自 cordova plugin code here on line #182.,它引用了 Android 类。

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

【问题讨论】:

    标签: android ionic-framework ionic2 cordova-plugins geocoder


    【解决方案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;
            }

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-09-20
        • 1970-01-01
        • 2020-03-24
        • 1970-01-01
        • 2011-03-18
        • 2021-05-13
        • 1970-01-01
        相关资源
        最近更新 更多