google map - database connection

Hello everyone,
I’m creating a website for real estate agency using database and I want to put google map on a dynamic page. I have a database with houses containing latitude and longitude:

and a google map on each dynamic page into which I want to import data from the database:

I’m using this code:

let myLocation = $w(“#googleMaps1”).location;

let txtGoogleMaps1 = $w(‘#dataset1’).getCurrentItem().Title;
let txtGoogleMaps1Lat = $w(‘#dataset1’).getCurrentItem().latitude;
let txtGoogleMaps1Long = $w(‘#dataset1’).getCurrentItem().longitude;

    $w("#googleMaps1").location = { 

“longitude”: txtGoogleMaps1Long,
“latitude”: txtGoogleMaps1Lat,
“description”: txtGoogleMaps1 }

It doesn’t work though and I’m still confused with the code so I have no idea why. Would anyone tell me, what exactly does the code mean and how to fix it? (e. g. why is there “txt” in txtGooleMapsName? getCurrentItem() should pick the value from the right row of the database defined by the current dynamic page or title? and should there be some value between the brackets? Is the word longitude from getCurrentItem().longitude; actually picking data from longitude column in the database? And isn’t it all kind of cycled, when last three rows of the code refer to the previous three rows of the code?)

I’m sorry for a complicated query, but if I could fix it somehow, it would be awesome and if I would even understand it, it would be even better! :smiley:

Thank you very much for any advice! :slight_smile:


Have you checked of the coordinates that you get from the collection are string or number?
Note that according to the documentation , they should be numbers. You can use the parseFloat function for that purpose.

Good luck,

Hi Tal,
I think that it was a number, but the code wasn’t connected to the database correctly. Now it works. Thanks for the reply.


1 Like

Hi All,
I had the same requirement as well and have implemented it on my website. Here is an example for those that need a reference guide.
Cheers, Ben

Hi, I’m building something similar, but don’t have the lat and long… just the address. I’ve searched the Google API SDK and can’t find the correct code to convert address to lat and long. I have everything else hooked up and have my API key. Anyone know of a code snippet that works?

Hi Charles,

You can check out this thread,

It worked for me! Good luck.