Chrome 中的地理位置提示对话框,我该如何实现?

Geolocation prompt dialog in Chrome, how do I implement that?

我需要在 Web 浏览器中实现设备地理位置的提示对话框,但我有点不知如何去做。我有这个 JavaScript 代码:

if (navigator.geolocation) {
  // Prompt for permision
  navigator.geolocation.getCurrentPosition()
  } 
else {
    alert('Please allow your location in order for app to work 
    properly.');
  }

但是 getCurrentPosition 需要至少 1 个参数,我似乎无法让它工作。

我在网上找到的所有 JavaScript 代码都可以正常工作,但它们都是在控制台中编写的 Your latitude is:Your longitude is: 但我不需要那个.

我需要网络浏览器只记住地理位置,以便稍后在 Foursquare 中使用坐标 API。我不需要浏览器在 Web 浏览器的控制台中写入任何内容。

but getCurrentPosition requires at least 1 argument and I can't seem to get it working.

所以你需要一个例子来说明如何传递合适的参数。

All the JavaScript code that I've found online worked just fine, but all of them were writing in the console Your latitude is: and Your longitude is: but I don't need that.

所以你有如何传递参数的例子。该参数是一个对位置做某事的函数。你只是不喜欢它对职位的影响。

使用那个例子。

编辑函数,让记录信息的行代替您对数据执行您想做的任何事情。

这里是the version from MDN:

var options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
};

function success(pos) {
  var crd = pos.coords;

  console.log('Your current position is:');
  console.log(`Latitude : ${crd.latitude}`);
  console.log(`Longitude: ${crd.longitude}`);
  console.log(`More or less ${crd.accuracy} meters.`);
};

function error(err) {
  console.warn(`ERROR(${err.code}): ${err.message}`);
};

navigator.geolocation.getCurrentPosition(success, error, options);