Hi,
Firstly apologies, I have asked this question a couple times already on this forum, both as its own post and in the comments of other posts, but I have still not been able to find an answer. So any help would be greatly appreciated.
I have followed the below example:
https://www.wix.com/corvid/forum/corvid-tips-and-updates/example-multiple-markers-google-maps
I have been able to create a map with multiple markers all coming from my database. I would now like to centre the map on the users location.
I have found bits of advise on this forum and via google, but haven't been able to get it to work. Could anyone tell me how to change the code in the example above so that it centres on the user.
Many thanks - this has been frustrating me for awhile!
The code to center the map to a location is in the HtmlComponent code of the Multiple Markers Google Map example that you reference.
Looking at the code in the HtmlComponent, you will see:
let barcelona = {lat: 41.38506389999999, lng: 2.1734035}; ... lots of other code ... let map = new google.maps.Map(document.getElementById('map'), { zoom: 2, streetViewControl: false, center: barcelona // Barcelona is a good center point });
Take a look at getCurrentGeolocation( ) function : https://www.wix.com/corvid/reference/wix-window.html#getCurrentGeolocation
It returns the current geolocation of the user.
Your code will look something like this:
import wixWindow from 'wix-window'; wixWindow.getCurrentGeolocation() .then((obj) => { let timestamp = obj.timestamp; // 1495027186984 let latitude = obj.coords.latitude; // 32.0971036 let longitude = obj.coords.longitude; // 34.774391099999995 let altitude = obj.coords.altitude; // null let accuracy = obj.coords.accuracy; // 29 let altAccuracy = obj.coords.altitudeAccuracy; // null let heading = obj.coords.heading; // null let speed = obj.coords.speed; $w.onReady(function () { $w("#myGoogleMap").location = { "latitude": latitude, "longitude": longitude, "description": "I am here" }; }); })