<?php
/**根据一组经纬度查找附近2公里以内的关键字**/
header('Content-type:text/html;charset=utf-8');
//--------第一步:转换经纬度----
//参考链接:http://developer.baidu.com/map/index.php?title=webapi/guide/changeposition
$Location_X = 23.134521;
$Location_Y = 113.358803;
$url = "http://api.map.baidu.com/geoconv/v1/?coords=$Location_X,$Location_Y&from=3&to=5&ak=这里填写你的apikey";
$res = file_get_contents($url);
$res = json_decode($res, true);
//用户发送腾讯的soso地图位置信息经过转换之后,得到百度地图的经纬度
$x = $res['result'][0]['x'];
$y = $res['result'][0]['y'];
//---------第二步:根据经纬度和关键词获得附近的信息----------
//参考链接:http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-placeapi
$url = "http://api.map.baidu.com/place/v2/search?ak=这里填写你的apikey&output=json&query=" . urlencode("饭店") . "&page_size=10&page_num=0&scope=2&location=$x,$y&radius=2000";
$res = file_get_contents($url);
$res = json_decode($res, true);
// echo "<pre>";
// print_r($res);
// echo "</pre>";
//提取所需的信息
foreach($res['results'] as $k=>$v){
$arr[$k]['name'] = $v['name'];
$arr[$k]['address'] = $v['address'];
$arr[$k]['img_url'] = 'http://misakaqnxt-public.stor.sinaapp.com/click.png';
$arr[$k]['detail_url'] = isset($v['detail_info']['detail_url'])?$v['detail_info']['detail_url']:'';
}
echo "<pre>";
print_r($arr);
echo "</pre>";
elseif($which == "寻找"){
$find = str_replace($which, "", $keyword);
//调用新浪云的KVDB服务
$kv = new SaeKV();
$kv->init();
$kv->set('find', $find);
$contentStr = "选择表情旁边的'+',发送位置,即可查找你要找的地方";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgtype, $contentStr);
echo $resultStr;
exit();
}
elseif($postObj->MsgType == 'location'){
/**
* 如果是收到了地理位置消息,则返回附近的饭店
*/
//--------第一步:转换经纬度-------
//参考链接:http://developer.baidu.com/map/index.php?title=webapi/guide/changeposition
$Location_X = $postObj->Location_X;
$Location_Y = $postObj->Location_Y;
$url = "http://api.map.baidu.com/geoconv/v1/?coords=$Location_X,$Location_Y&from=3&to=5&ak=这里填写你的apikey";
$res = file_get_contents($url);
$res = json_decode($res, true);
//用户发送腾讯的soso地图位置信息经过转换之后,得到百度地图的经纬度
$x = $res['result'][0]['x'];
$y = $res['result'][0]['y'];
//---------第二步:根据经纬度和关键词获得附近的信息----------
$kv = new SaeKV();
// 初始化KVClient对象
$kv->init();
$url = "http://api.map.baidu.com/place/v2/search?ak=这里填写你的apikey&output=json&query=" . urlencode($kv->get('find')) . "&page_size=10&page_num=0&scope=2&location=$x,$y&radius=2000";
$res = file_get_contents($url);
$res = json_decode($res, true);
//提取信息
foreach($res['results'] as $k=>$v){
$arr[$k]['name'] = $v['name'];
$arr[$k]['address'] = $v['address'];
$arr[$k]['img_url'] = 'http://misakaqnxt-public.stor.sinaapp.com/click.png';
$arr[$k]['detail_url'] = isset($v['detail_info']['detail_url'])?$v['detail_info']['detail_url']:'';
}
//--------第三步:拼接XML字符串--------
$head = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>10</ArticleCount>
<Articles>";
$items = "";
foreach($arr as $v){
$items .= "<item>
<Title><![CDATA[" . $v['name'] .":". $v['address'] . "]]></Title>
<Description><![CDATA[" . $v['address'] . "]]></Description>
<PicUrl><![CDATA[" . $v['img_url'] . "]]></PicUrl>
<Url><![CDATA[" . $v['detail_url'] . "]]></Url>
</item>";
}
$foot = "</Articles></xml>";
$res = $head . $items . $foot;
$resultStr = sprintf($res, $fromUsername, $toUsername, $time);
echo $resultStr;
exit();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有