Geocoding with google

Hello, google tells me to use this line in the code, var geocoder = new google.maps.Geocoder(); if i use it i get an error ReferenceError: google is not defined …what i miss?

It means that ‘google’ hasn’t been defined anywhere. Where is it defined in your project?

It isn’t…nowhere is write to define it…also if i suposed it was necessary to define it…i searched on google lot of times but i haven’t found a decent explanation.

Oh right…happy 2017 :slight_smile:

If you check the samples from the Google Maps API documentation, you can see how they have included the JS SDK into their page:

You mean this? good point …all the examples are for html pages, i have checked my project on google and it has the geocoding api enabled, i also found this,-73.961452&key=YOUR_API_KEY and still don’t get how to use all this in Playcanvas.
I have copied in this js the file given by google but i think i have to rewrite some parts of it … totally lost

Very quickly did a sample project to test which looks like it works:

Not sure what you are looking to achieve though?

Uhm, what i want to achieve is the reverse geocoding for lat and lng get the address.

That seems to be pretty straightforward. What problems are you running into at the moment?

Yes it should be not difficult so that means i’m dumb :stuck_out_tongue: now i have got this error
InvalidValueError: in property latLng: not a LatLng or LatLngLiteral: not an Object
given by this

geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[0]) {
                        alert("Location: " + results[0].formatted_address);
                        return (results[0].formatted_address);

How have you initialised the variable ‘latlng’?

var latlng=this.latlng; and this.latlng=lat+’,’+lng; in different functions that’s why the double equality

latLng is a class that is defined in the Google SDK and is what geocode is expecting as a parameter:

mmhh i really start to hate google maps now :angry: i feel like a mouse in a wheel

A step forward, al least i got an error over_query_limit :slight_smile: never thought i would be happy to see an error lol