Fetching a user's position

To actually fetch a user's position we're going to use a function available on geolocation. To access it we'll add navigator.geolocation.getCurrentPosition inside the locationButton.on function next to the if statement. The getCurrentPosition function is a function that starts the process. It's going to actively get the coordinates for the user. In this case, it's going to find the coordinates based off of the browser, and this takes two functions. The first one is your success function, right here we can add our first callback. This is going to get called with the location information, we're going to name this argument position:

  navigator.geolocation.getCurrentPosition(function (position) { 
  } 
}); 

The second argument ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.