Get user's location and return on map



I’m creating a project for displaying a user’s location on a map and showing available restaurants near by

I am using, open external link with the following javascript to get the user’s location

function getLocation(callback) {
if (navigator.geolocation) {
    var lat_lng = navigator.geolocation.getCurrentPosition(function(position){
      var user_position = {}; = position.coords.latitude; 
      user_position.lng = position.coords.longitude; 
} else {
    alert("Geolocation is not supported by this browser.");

Which works for getting the user’s lat long but I’m now stuck trying to work out how to get the lat long in order for me to add it to google maps parameter for returning their location

Any ideas/solutions would be greatly appreciated! :fist_right::fist_left:


You should have access to an object with lat and lng properties in the callback you’re passing to getLocation. Currently you’re printing it to the console but use the lat_lng object in your callback to do what you need with it.

What do you want to do with it, specifically?


Is there a way to intercept the callback and pass that into a global variable?

I’m going to use the lat long to mark the user’s location on the map

So adding the lat lng to;


Add this to the callback function:

$axure.setGlobalVariable('axureLngVariable', lat_lng.lng);

Rename the Axure variables if you want. You can then use them to format the link like you posted. I don’t know how the URL is supposed to be formatted but it’s probably something like:[[axureLatVariable]],[[axureLngVariable]]

You’ll have to modify that to format it correctly probably. It’s also possible that the lat and lng might need to be formatted by the callback function before setting the Axure variable. Just a guess because I have no idea what the Maps URL is expecting or what the device location API returns.


I would also like to demonstrate this in an axure prototype, is there any material to help me learn how to implement it?

unlisted #6

closed #7