Searching for google non-angular geolocation

-1

Hello, I have to search for Longitude and Latitude, by the Google API, with Angular ..

I am using this code to make the request:

constructor(private http: Http, private vwServicePagination: VwServicePagination){}

    obtendoGeolocalizacao() {  
        return this.http.get('https://maps.googleapis.com/maps/api/geocode/json?address=09771220')
            .map(response => response.json());
    }

And here in OnInit I'm calling this method created above ... This way:

ngOnInit(){
        const teste = this.vwServiceApi.obtendoGeolocalizacao();
        
        console.log(this.teste);
    }

However, the returned object has nothing to do with the json that is returned by the API! How do I get the JSON object returned by the API?

    
asked by anonymous 16.04.2018 / 16:04

1 answer

1

I used the following way to get the object ...

this.vwServiceApi.obtendoGeolocalizacao().subscribe(res => {this.apiGoogle = res.json();                
                this.lat = this.apiGoogle.results[0].geometry.location.lat;
                const lng = this.apiGoogle.results[0].geometry.location.lng;
                const uf = this.apiGoogle.results[0].address_components[3].short_name;               
            });     
    
16.04.2018 / 19:53