地理位置和php和数据库


Geolocation and php and database

我想在我的phpwebsite中使用地理位置。那我做了什么。用户可以添加名称,街道,门牌号等信息。到数据库。此信息清楚地存储在数据库中。如果人们使用搜索功能查找地点,他们会收到他们搜索过的地点列表。在列表中的每个成立地点,用户可以单击 en 他们会收到有关特定地点(记录)的更详细页面。在此页面中,必须有地理位置。我已经使用过谷歌,我发现我需要将地址转换为纬度/经度。这个纬度和经度必须添加到数据库中,但我不知道在什么时候(已经在 add 函数中,在单独的函数中之后)以及我将如何执行此操作。此时我有一个计算经度和纬度的函数。我将它们存储在 javascript 中的 2 个变量中,但现在我卡住了。在这里,您可以看到我已经拥有的代码。

<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>

您将其他字段保存到数据库中的什么位置? 为什么不在同一点对经度和经度进行地理编码和存储呢?