Reputation: 5091
I require to load the values from google map. for that I trying like this:
public getCountry(lang,lat):Observable<any>{
console.log( lang, lat );
return this.http.get('http://maps.googleapis.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false');
}
But getting no result. how can i load the data from the above url?
any one help me?
update
if(navigator){
navigator.geolocation.getCurrentPosition( pos => {
this.latitude = pos.coords.latitude;
this.longitude = pos.coords.longitude;
let data = this.server.getCountry(("latlng="+this.latitude+","), this.longitude);
console.log('data', data );
})
}
Upvotes: 1
Views: 65
Reputation: 239
Use this
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
instead of
http://maps.googleapis.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false
because you fetching xml data not json
Upvotes: 1
Reputation: 15313
Based on the other answer, you might have to modify the way you call the API, but you also have to subscribe to your function in order to access the returned value.
this.server.getCountry(("latlng="+this.latitude+","), this.longitude)
.subscribe(data => {
console.log(data);
})
Upvotes: 1