user2024080
user2024080

Reputation: 5091

How to load the value in angular using `rxJS`

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

Answers (2)

Parth Godhani
Parth Godhani

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

bugs
bugs

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

Related Questions