PHP,谷歌地理编码,传递信息

PHP,谷歌地理编码,传递信息,php,javascript,google-maps,google-geocoder,Php,Javascript,Google Maps,Google Geocoder,我有一个php页面。 php页面有一个表单,当我点击按钮时,它会调用页面本身。如果值为'submit',则调用API以显示属性统计信息 这很好用。但是我不想使用位置(与表单一起传递),而是想使用google geocode返回的东北和西南坐标 我已经设法对我的位置进行了地理编码。但我正在努力将数据从地理代码(javascript)传递到我的php页面 最佳做法是什么 编辑描述 这是我的表格电话: <form action="http://www.propertycrunch

我有一个php页面。 php页面有一个表单,当我点击按钮时,它会调用页面本身。如果值为'submit',则调用API以显示属性统计信息

这很好用。但是我不想使用位置(与表单一起传递),而是想使用google geocode返回的东北和西南坐标

我已经设法对我的位置进行了地理编码。但我正在努力将数据从地理代码(javascript)传递到我的php页面

最佳做法是什么

编辑描述

这是我的表格电话:

        <form action="http://www.propertycrunch.co.uk/investment-analysis/" method="post" onsubmit="nesw(this.location.value);">
            <input id="location" name="Location" class="searchbox"/> 
            <input type="submit" name="submit" value="Search" id="submitbutton" /> 
        </form>

<script type="text/javascript">
  function nesw(strAddress) {
        //initialize();
        var geocoder;
        var map;
        var address = strAddress;
        // set up Google map, pass in the heatmap function
        var myOptions = {
            zoom: 6,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            scaleControl: true
        }
        var map = new google.maps.Map(document.getElementById("heatmap"), myOptions);
        if (address) {
            alert('Address: ' + address);
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode( { 'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location) ;
                    var ne = results[0].geometry.viewport.getNorthEast();
                    var sw = results[0].geometry.viewport.getSouthWest();
                }
            });

        }
        alert('coordinates: ' + ne + ' / ' + sw);
  } 
</script>

功能nesw(跨装){
//初始化();
var地理编码器;
var映射;
var地址=地址;
//设置谷歌地图,传递热图功能
变量myOptions={
缩放:6,
mapTypeId:google.maps.mapTypeId.ROADMAP,
scaleControl:对
}
var map=new google.maps.map(document.getElementById(“热图”),myOptions);
如果(地址){
警报(“地址:”+地址);
var geocoder=new google.maps.geocoder();
geocoder.geocode({'address':address},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
map.setCenter(结果[0].geometry.location);
var ne=results[0]。geometry.viewport.getNorthEast();
var sw=results[0]。geometry.viewport.getsoutwest();
}
});
}
警报('坐标:'+ne+'/'+sw);
} 
问候,,
Olivier

为表单中的4个值(NElat、NElng、SWlat、SWlng)创建4个隐藏字段,并在获得地理编码结果时设置值。

您能提供您正在处理的相关代码吗?你好,Molle博士。我也这么想。我现在看到的是一个称为PHP页面本身的表单。有一个参数,如果该值是submit,那么我将通过调用API进行处理。我还显示了谷歌地图。一切正常。现在,在我的表单调用中,我添加了一个onsubmit选项来调用Javascript函数。我想让那个函数对我输入的位置进行地理编码。我能够将地址传递给我的javascript函数。但是地理编码失败了(或者没有返回任何东西)。我不知道为什么。我将尝试在我的主要描述中添加代码,因为我认为我无法在注释框中添加代码。您不能这样做,地理编码结果将异步获取,因此表单将在您收到结果之前提交。您可以在函数中取消表单的提交,并在收到响应后立即提交表单。当然,您也可以跳过客户端请求,使用PHP请求结果。