I successfully get an answer from the Google Map Javascript Api and try to access the values of the google.maps.GeocoderResult to extract the latitude and longitude from the GeocoderGeometry / LatLng
I implemented response.data[0].geometry.location.lat(), following the TSD definition, which lead, while debugging in Chrome, to the error:
TypeError: response.data[0].geometry.location.lat is not a function
Having a look at the object in the debugger, show effectively that no method lat() or lng() aren't supported.
I could access to response.data[0].geometry.location.lat to successfully get the value in the debugger, but then my code isn't Typescript conform anymore.
Of course I could cast the result but still would like to understand the reason. Furthermore maybe someone has got an explanation and proposition of solution?
Best regards
For the record, the typescript definition:
Update with chrome debug info:
response.data[0].geometry.location.lat() => <not available>
response.data[0].geometry.location.lat: 47.37793800000001
response.data[0].geometry.location: Object
lat: 47.37793800000001
lng: 8.5401898
response.data[0].geometry: Object
location:Object
lat:47.377
lng: 8.5401898
stacktrace of the error:
TypeError: response.data[0].geometry.location.lat is not a function
at interestsParamsCtrl.js:61
at processQueue (ionic.bundle.js:29127)
at ionic.bundle.js:29143
at Scope.$eval (ionic.bundle.js:30395)
at Scope.$digest (ionic.bundle.js:30211)
at Scope.$apply (ionic.bundle.js:30503)
at done (ionic.bundle.js:24824)
at completeRequest (ionic.bundle.js:25022)
at XMLHttpRequest.requestLoaded (ionic.bundle.js:24963)
Update 2: To query the API I do a GET and let the response be parsed
search(searchLocationTerm:string):ng.IPromise<{}> {
var deferred = this.$q.defer();
this.$http.get(Resources.Constants.Default.GOOGLE.API.URL,
{
params: {
address: searchLocationTerm,
key: Resources.Constants.Default.GOOGLE.API.KEY
}
})
.success((response:Communication.IGeocoder) => {
deferred.resolve(response);
}).error((response:Communication.IGeocoder) => {
deferred.reject(response);
});
return deferred.promise;
};
Where IGeocoder is
export interface IGeocoder {
results:google.maps.GeocoderResult[];
status:google.maps.GeocoderStatus;
}
response.data[0].geometry.locationif you output it to the console?LatLngLiteralinstead ofLatLngobject. Maybe your error also comes because of this.