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:
![](https://static.wixstatic.com/media/a27d24_97012a524d844ac5b10b75ff460aa118~mv2.jpg/v1/fill/w_980,h_253,al_c,q_80,usm_0.66_1.00_0.01,enc_auto/a27d24_97012a524d844ac5b10b75ff460aa118~mv2.jpg)
and a google map on each dynamic page into which I want to import data from the database:
![](https://static.wixstatic.com/media/a27d24_18b25fee6cf940ff95d89db37832b11b~mv2.png/v1/fill/w_980,h_1800,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/a27d24_18b25fee6cf940ff95d89db37832b11b~mv2.png)
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 }
![](https://static.wixstatic.com/media/a27d24_07904effaab549bfa07fd9293016d0b9~mv2.jpg/v1/fill/w_906,h_640,al_c,q_85,enc_auto/a27d24_07904effaab549bfa07fd9293016d0b9~mv2.jpg)
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! :D
Thank you very much for any advice! :)
Dasha
Hi Charles,
You can check out this thread, https://www.wix.com/code/home/forum/wix-tips-and-updates/how-to-use-google-maps-services-in-wix-code
It worked for me! Good luck.
Regards,
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 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 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.
Dasha
Hi,
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,
Tal,