Ionic-native: Native Reverse Geocoder

Created on 31 Jul 2017  路  8Comments  路  Source: ionic-team/ionic-native

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request

Current behavior:
When using nativeGeocoder.reverseGeocode, the result is instance of NativeGeocoderReverseResult, and the interface is :

export interface NativeGeocoderReverseResult { /** * The street. */ street: string; /** * The house number. */ houseNumber: string; /** * The postal code. */ postalCode: string; /** * The city. */ city: string; /** * The district. */ district: string; /** * The country name. */ countryName: string; /** * The country code. */ countryCode: string; }

But in the result object there is :

{"administrativeArea": "XXXXX", "countryCode": "XXXX", "countryName": "XXXX", "locality": "XXXXX", "postalCode": "1235", "subAdministrativeArea": "XXXX", "subThoroughfare": "1", "thoroughfare": "Rue XXXXX"}

Expected behavior:

having the interface mapped to the correct attribute names.

Steps to reproduce:

Use this in a component ( after loaded each needed modules )

this.geolocation.getCurrentPosition().then((resp) => { this.nativeGeocoder.reverseGeocode(resp.coords.latitude, resp.coords.longitude).then( ...

Related code:

 */
export interface NativeGeocoderReverseResult {
    /**
     * The street.
     */
    street: string;
    /**
     * The house number.
     */
    houseNumber: string;
    /**
     * The postal code.
     */
    postalCode: string;
    /**
     * The city.
     */
    city: string;
    /**
     * The district.
     */
    district: string;
    /**
     * The country name.
     */
    countryName: string;
    /**
     * The country code.
     */
    countryCode: string;
}

Other information:

To fix it change the interface with the correct attributes

package.json info:

insert the content here

Most helpful comment

Here is a temp fix if anyone needs it before it is fixed:

Create a custom interface

export interface NativeGeocoderResultModel {
  subAdministrativeArea: string,
  postalCode: number,
  locality: string,
  subLocality: string,
  subThoroughfare: string,
  countryCode: string,
  countryName: string,
  administrativeArea: string,
  thoroughfare: string
}

Then create an object using that interface and set it equal to the parsed, stringified result

let newResult: NativeGeocoderResultModel = JSON.parse(JSON.stringify(result));

Now you can grab the new result and manipulate it however you would like.

All 8 comments

Was about to leave the same issue with all the same information. Please fix.

Here is a temp fix if anyone needs it before it is fixed:

Create a custom interface

export interface NativeGeocoderResultModel {
  subAdministrativeArea: string,
  postalCode: number,
  locality: string,
  subLocality: string,
  subThoroughfare: string,
  countryCode: string,
  countryName: string,
  administrativeArea: string,
  thoroughfare: string
}

Then create an object using that interface and set it equal to the parsed, stringified result

let newResult: NativeGeocoderResultModel = JSON.parse(JSON.stringify(result));

Now you can grab the new result and manipulate it however you would like.

@gabriellecozart YOU ARE A LIFE SAVER! Thanks girl!

@monichols Glad I could help!

ran into this.. looks like it's an easy fix Will submit PR shortly

turns out there is already a PR for this #1840

Could someone take a look at this? The fix is already done on #1840, someone could merge it?

when i am starting this cmd: ionic cordova build android --proud

Typescript Error
Property 'countryName' does not exist on type 'NativeGeocoderReverseResult[]'.

Was this page helpful?
0 / 5 - 0 ratings