I am using CoffeeScript, Backbone.js and Google Maps API to reverse geocode a lat / lng
I have the function
country: (origin, callback) ->
@geocoder = new google.maps.Geocoder
@geocoder.geocode(
'latLng': origin,
(results, status) =>
if status is google.maps.GeocoderStatus.OK
callback(result[6])
else alert("Geocode was not successful for the following reason: " + status);
)
When I call this I use:
@country(origin, (data) =>
console.log(data.formatted_address)
)
btw:
origin = new google.maps.LatLng(origin_lat, origin_lng)
This does not work, it does not even seem to call it. I have the call back function under (data) but can not get it to work…
Thanks
Not sure about the overall context of your question, but I will take a stab at it anyway.
The way you’ve defined your country function, it will typically be part of an object or map. If you just want a standalone function, try:
Then when calling it, try to replace
@country(...)withcountry(...).Based on the comments, your call to geocode also looks wrong. You need to create an instance of GeocoderRequest and pass it instead of the
'latLng': originpair. Unfortunately I haven’t used the Google style APIs much, so if this is your real question I’m not much use to you.