-1

I have used the tutorial here http://tech.cibul.net/geocode-with-google-maps-api-v3/ to create a page with map and draggable marker to display address and lat/long.

Demo - http://www.calcunation.com/testgeo.php

How do I captured those results and put them into a php variable so I can insert into a mysql database?

I'm relatively new to Java, and fairly comfortable with PHP.

4

2 回答 2

0

您是否尝试拆分地址组件?

像街道,城市,州,邮编......

如果是这样...您将需要查看地理编码结果,并解析它返回的地址类型数组。

这是一些您可以使用的快速示例代码...

//Startup a new geocode instance

var geocoder = new google.maps.Geocoder();

//event.latLng is a latLng object passed into the geocode function to get 
your addy results

geocoder.geocode({'location': event.latLng}, function(results, status) {

//Show the results here
console.log(results);

if (status == google.maps.GeocoderStatus.OK) {

    var addressResults = results[0].address_components;
    var address1 = "";
    var address2 = "";
    var city = "";
    var state = "";
    var zipCode = "";

    for(var i = 0; i < addressResults.length; i++){

        for(var j = 0; j < addressResults[i].types.length; j++){
            if(addressResults[i].types[j] == 'street_number'){
                address1 = addressResults[i].long_name;
                break;
            }

            if(addressResults[i].types[j] == 'route'){
                address1 += " " + addressResults[i].long_name;
                break;
            }

            if(addressResults[i].types[j] == 'subpremise'){
                address2 = addressResults[i].long_name;
                break;
            }

            if(addressResults[i].types[j] == 'locality'){
                city = addressResults[i].long_name;
                break;
            }

            if(addressResults[i].types[j] == 'administrative_area_level_1'){
                state = addressResults[i].short_name;
                break;
            }

            if(addressResults[i].types[j] == 'postal_code'){
                zipCode = addressResults[i].long_name;
                break;
            }
        }
    }

    //Do ajax post to your form here with the data you just parsed out
}
});
于 2012-09-14T18:43:11.850 回答
0

从用户的角度来看,AJAX 将是最干净的。我会使用 jquery $.post 来做http://api.jquery.com/jQuery.post/

于 2012-09-13T16:44:49.107 回答