【问题标题】:How to pass reverse geocoded adress back to a variable如何将反向地理编码地址传递回变量
【发布时间】:2012-03-08 01:11:45
【问题描述】:

如何“简单”地从地理编码器中提取地址值 我的代码如下所示:

之前的一些事情......

geocoder.geocode({latLng: 'mylatlon'}, function(results, status) {
   if (status == google.maps.GeocoderStatus.OK) {
                     if (results[0]) {
                    //alert(results[0].formatted_address);
                    thisadr=results[0].formatted_address;  
                         }}});';

...之后的一些事情,例如地图标题:thisadr 或 infowindow.content(thisadr 没有

虽然它可以完美运行(如果我相信 alert),但我无法将 thisadr var 移出这里

我花了很多时间试图寻找一个相当直接的解决方案,但无济于事

然后我有一个次要问题 我 PHP 构建了一个 html 表来提供信息窗口

所以有时我需要将该 html 表与该 thisadr 变量混合

到目前为止,我的信息窗口看起来像

var contenuInfoBulle'.$camindex.' =  \''.$phpbul.'\';

我想展示什么

 var contenuInfoBulle'.$camindex.' = thisadr  \''.$phpbul.'\';

【问题讨论】:

标签: javascript api google-maps geocoding reverse


【解决方案1】:

我设法回答了我自己的问题

1/ 通过在地理编码器请求中包含所有需要的内容,同时创建索引函数并随后为每个索引标记调用它

echo 'function buildmarker'. ($camindex). '(location) {';
echo 'geocoder = new google.maps.Geocoder();';

echo "geocoder.geocode({'latLng': location}, function(results, status) {";
echo "   rue='Adresse à déterminer';";
echo '   if (status == google.maps.GeocoderStatus.OK) {';
echo '        if (results[0]) {';
echo '          adress=results[0].formatted_address;';
echo "          elts=adress.split(',');";
echo '          rue=elts[0];';
echo '        }';

echo '      }';

echo 'var   contenuInfoBulle =  rue+\''.'<br>'.$phpbul.'\';';
echo 'var infoBulle = new google.maps.InfoWindow({ content: contenuInfoBulle });';
echo 'var thisicon = new google.maps.MarkerImage("../img    /marker'.$coulgoog.$ajout.'.png",null, null, null, new google.maps.Size(25, 25));';
echo 'var optionscam= {position: location,map: macarte,title:  "'.$camindex.'     '.$shortcam.'"   ,icon: thisicon};';
echo 'var mark = new google.maps.Marker(optionscam);';
echo 'google.maps.event.addListener(mark, "click", function() {infoBulle.open(macarte, mark)});';
echo 'var optionsCercle = {center: location,map: macarte,radius: 20 ,strokeWeight: 0};';
echo 'var monCercle = new google.maps.Circle(optionsCercle);';


echo '    });';
echo '} ';            //func

///////////////////////


echo "var cam". ($camindex). " = new google.maps.LatLng(".$myloc.");";
echo "buildmarker". ($camindex). "(cam".($camindex).");";

2/ 通过混合 JS/googmap 变量和预制 PHP/HTML 内容

echo 'var   contenuInfoBulle =  rue+\''.'<br>'.$phpbul.'\';';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    相关资源
    最近更新 更多