12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="Generator" content="EditPlus®">
- <meta name="Author" content="">
- <meta name="Keywords" content="">
- <meta name="Description" content="">
- <title>Document</title>
- <script src="jquery-3.1.0.js"></script>
- <script type="text/javascript">
- <!--
- /**
- * 获取地址对应的坐标
- * @param $address
- * @return array
- */
- function getAddressPoint($address){
- $lng = 0;
- $lat = 0;
- $url = 'http://api.map.baidu.com/geocoder?output=json&address='.urlencode($address);
- if(function_exists('curl_init')) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- $data = curl_exec($ch);
- curl_close($ch);
- }else{
- $data = file_get_contents($url,false,stream_context_create(array(
- "http"=>array(
- "method"=>"GET",
- "timeout"=>1
- ),
- )));
- }
-
- $data = json_decode($data,true);
- if($data && $data['status'] == 'OK' && isset($data['result']) && isset($data['result']['location']))
- {
- $lng = $data['result']['location']['lng'];
- $lat = $data['result']['location']['lat'];
- }
- return array($lng,$lat);
- }
- //-->
- </script>
- </head>
- <body>
- <button onclick="getAddressPoint('宛平南路75号')">获取经纬度</button>
- </body>
- </html>
|