我需要从地址获取经纬度,使用谷歌地图,并用php操纵它。从Javascript/Geocoder.geocode()获取经度和纬度并使用它与PHP
我用这样一个https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple代码,具有该部分:
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
,我已经添加了变数纬度和经度(按照this question中的说明现在,我需要使用变量我已经在Java脚本中的PHP脚本创建的。
我新手到JavaScript,因此,我很抱歉,如果这是一个简单的问题。
如果你只是想打印出坐标到您的网页,(<?PHP的echo()>为您的''例子说明)你可以使用JavaScript来做到这一点,不需要使用PHP。你能澄清一下你需要将这些协议传递给PHP吗? – duncan 2014-09-11 08:28:13
我不是简单地打印出坐标,这是保持简单问题的一个例子。我需要发送坐标到setcookie()和一个外部程序来处理它并给出一个输出。这很容易,我没有任何问题可以用PHP来完成,为什么我想要传递变量。 – 2014-09-11 13:32:09
@duncan我编辑了这个问题,希望现在好一点。 – 2014-09-11 15:52:03