嗨,我正在尝试创建一个商店定位器,我想将用户的纬度和经度放到数据库中我该怎么做我正在使用 javascript 来获取结果,我将使用 php 作为数据库这是代码我用来获取用户位置
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition1(position) {
var locations = [
['store1', -2.063150, 2.516503, 4],
['store2', -2.064824, 52.518436, 5],
['store3', -2.068214, 52.519898, 3],
['store4', -2.068558, 52.512769, 2],
['store5', -2.070875, 52.510758, 1]
];
lon1 = position.coords.longitude * 0.0174532925;
lat1 = position.coords.latitude * 0.0174532925;
i = 0;
while (i < locations.length) {
function round(x) {
return Math.round(x * 10) / 10;
}
x.innerHTML += "<br>Distance " + round(calcDist(lon1, lat1, locations[i][1] * 0.0174532925, locations[i][2] * 0.0174532925));
i++;
}
}
我所有的代码都在工作我只是希望能够将 lon 1 和 lat1 放入我的数据库中,任何想法都会非常感谢提前谢谢