百度地图接口开发

baidumap.html
<script>

var is_location = 0; //获取所在地的经纬度
 function getLocation() {
  if (navigator.geolocation) {  
   navigator.geolocation.getCurrentPosition(showPosition);
  }
 }
 function showPosition(position) {
  //根据IP定位http://api.map.baidu.com/location/ip?ak=lWp1O5BZuqVI6aLsZobgfAvq&ip=202.198.16.3&coor=bd09ll
  //根据地理位置http://api.map.baidu.com/geocoder/v2/?ak=lWp1O5BZuqVI6aLsZobgfAvq&callback=renderReverse&location=29.554765397706273,106.4602094533912&output=json
  location.href = '/?lng=' + position.coords.longitude + '&lat=' + position.coords.latitude;
    //aaa='/?lng=' + position.coords.longitude + '&lat=' + position.coords.latitude;
 }

 if (is_location == 0) {
  getLocation();
  
 }

</script>

 

 

baiduinter.php

<?php

//根据用户经纬度获取具体信息
function getXyLocation($longitude,$latitude){
    $url="http://api.map.baidu.com/geocoder/v2/?ak=lWp1O5BZuqVI6aLsZobgfAvq&callback=renderReverse&location=$latitude,$longitude&output=json";
    $file_contents = curl_get_contents($url);
    $strstart=strpos($file_contents,'(');
    $strend=strpos($file_contents,')');//var_dump($strend);die($strstart);
    $file_contents=substr($file_contents,$strstart+1,$strend-$strstart-1);
    $content = json_decode($file_contents);
 return object2array($content);
}

$xyinfo=getXyLocation($lng,$lat));

print($xyinfo);

?>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值