0

我有一个 php 页面。php页面有一个表单,当我点击按钮时,它会调用页面本身。如果值为“提交”,那么我调用 API 来显示属性统计信息。

这工作正常。但我不想使用位置(通过表格传递),而是想使用谷歌地理编码返回的东北和西南坐标。

我已经设法对我的位置进行地理编码。但我正在努力将数据从地理编码(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>

问候,奥利维尔

4

1 回答 1

1

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

于 2012-03-05T22:20:01.400 回答