0
我想在我的phpwebsite使用地理定位。那么我做了什么。用户可以将名称,STREET,HOUSENUMBER等信息添加到数据库中。这些信息清楚地存储在数据库中。如果人们寻找具有搜索功能的地方,他们会收到他们搜索的地点列表。 在列表中的每个创建地点,用户可以点击en获得关于特定地点(记录)的更详细页面。在此页面中必须有地理位置。我已经使用谷歌,我发现我需要将地址转换为lattidude/longitude。这种经度和纬度必须添加到数据库中,但我不知道在什么时候(已经在添加函数中,在单独函数之后)以及我将如何执行此操作。此时我有一个计算经度和纬度的函数。我将它们存储到2个变量,在JavaScript中,但现在我卡住了。 在这里你看到我已经有的代码。地理位置和PHP和数据库
<script>
$(document).ready(function() {
// wire up button click
$('#go').click(function() {
// get the address the user entered
var straat = $('#straat').val();
var nummer = $('#nummer').val();
var address = straat + " " + nummer;
alert(address);
if (address) {
// use Google Maps API to geocode the address
// set up the Geocoder object
var geocoder = new google.maps.Geocoder();
// return the coordinates
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
// print results
printLatLong(results[0].geometry.location.lat(),
results[0].geometry.location.lng());
} else {
error('Google did not return any results.');
}
} else {
error("Reverse Geocoding failed due to: " + status);
}
});
}
else {
error('Please enter an address');
}
});
});
// output lat and long
function printLatLong(lat, long) {
var latitude = lat;
var longitude = long;
$('.results').text(latitude);
}
function error(msg) {
alert(msg);
}
</script>
这就是我想做的事,但我不知道怎么办。我有一个完整的PHP脚本来存储我的信息,但不是长/ LAT。我想同时存储这个,但是如何。 – Niels
啊,我明白了,你可以用PHP地理编码(谷歌有一个休息的API,你可以使用的file_get_contents或卷曲命中),如果你做的是,在原来的保存,你就会有这些数据点 –
https://开头开发商。 google.com/maps/documentation/geocoding/#GeocodingRequests –