Get Postal Code with GoogleMaps native


#1

How can I get the postal code with the native plugin GoogleMaps for ionic?

Thx


#2

You can get it with GeocoderRequest. See the docs:


#3

Yes, I dont know how make the code. Maybe this:

  doGeocode(marker) {
        let request: GeocoderRequest = {
            position: new LatLng(this.myPosition.latitude, this.myPosition.longitude),
        };
        this.geocoder.geocode(request)
            .then((res) => {
                //https://ionicframework.com/docs/native/google-maps/#GeocoderResult
                let results = res as GeocoderResult 
                let address = [
                    (results[0].thoroughfare || "") + " " + (results[0].subThoroughfare || ""),
                    results[0].locality
                ].join(", ");
                console.log("data_: ", address);
                marker.setTitle(address);
                marker.showInfoWindow();
            });
    }