Vorbly Code | WIX CODE GOOGLE MAPS LOCATION FROM DATABASE

Vorbly <Code>

CODING MADE EASY WITH VORBLY

WIX CODE GOOGLE MAPS LOCATION FROM DATABASE

Need a Google Map for your dynamic pages? This tutorial will show you how to add a Google Map with geolocations from a database. We will provide you with the webpage elements and sample codes required to implement this feature.

THE DEMO

1/3

THE ELEMENTS

The Page

Google Maps: #googleMaps1

The Database

Create a database: GoogleMaps (dataset1)

Recommended fields:

  • Geolocation Latitude: latitude

  • Geolocation Longitude: longitude

  • Location Name / Description: location

Tip: You can use Google Maps or other online tools to find the latitude and longitude of addresses.

Create a dynamic page.

The Dynamic Page

Create a dyanmic page: Product (Title)

Link fields on dynamic page to your database. Do not link your Google Maps, geolocation will be populated by code.

THE CODE

Page Code

$w.onReady( function () {

     $w("#dataset1").onReady( () => {

        let currentItem = $w("#dataset1").getCurrentItem();

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

             "latitude": currentItem.latitude,

             "longitude": currentItem.longitude,

             "description": currentItem.location,

        };

    });

});

COMMENTS

I'm a paragraph. Click here to add your own text and edit me. It's easy.

No comments. Be the first to leave a comment.

I implemented the above code, but it showing the following error when - 'Wix code SDK error: The longitude parameter is required for location method.'
Any ideas what is causing this or how to rectify as the longitude is included as above?

Chris Vale

Nov 27, 2018

0

Hi Chris,

You should ensure that your longitude and latitude fields are in number format and ensure that the coordinates are correct.

Next, ensure that your database permissions allow users to read from the datasets.

Good luck!

Ben (Vorbly)

Nov 27, 2018

1

I have checked this and i know am getting -
Wix code SDK Warning: The latitude parameter of "Dmap" that is passed to the location method cannot be set to null or undefined.
Wix code SDK error: The latitude parameter that is passed to the location method cannot be set to the value . It must be of type number.

Chris

Nov 27, 2018

1

All sorted now, thanks for your help :)

Chris Vale

Nov 27, 2018

1

We are glad you solved it!

Ben (Vorbly)

Nov 27, 2018

0

WEB DESIGN & DEVELOPMENT SOLUTIONS

GET PROFESSIONAL HELP