那么web网站呢,可以调用百度地图API进行相关处理达到类似的功能。
这里我采用elasticsearch来实现一个demo
1、搜索指定地点范围内的数据,
2、按某个指定点查找数据,并且进行数据的排序。
1、创建索引
$client = new Client();
$url = 'http://localhost:9200/cn_large_cities/';
$param = [
'json' => [
'mappings' => [
'city'=>[
'properties'=>[
'city'=>['type'=>'text'],
'state'=>['type'=>'text'],
'location'=>['type'=>'geo_point']
]
]
]
]
];
$res = $client->put($url,$param);
exit;
2、创建5条测试数据
$client = new Client();
$url = 'http://localhost:9200/cn_large_cities/city/1';
$param = [
'json' => [
'city' => 'Beijing',
'state'=>'BJ',
'location' => [
'lat'=>'39.91667',
'lon'=>'116.41667'
]
]
];
$res = $client->post($url,$param);
exit;
$client = new Client();
$url = 'http://localhost:9200/cn_large_cities/city/2';
$param = [
'json' => [
'city' => 'Shanghai',
'state'=>'SH',
'location' => [
'lat'=>'34.50000',
'lon'=>'121.43333'
]
]
];
$res = $client->post($url,$param);
exit;
$client = new Client();
$url = 'http://localhost:9200/cn_large_cities/city/3';
$param = [
'json' => [
'city' => 'Xiamen',
'state'=>'FJ',
'location' => [
'lat'=>'24.46667',
'lon'=>'118.10000'
]
]
];
其余代码可以访问我的网站博客,欢迎大家交流
http://www.huangxiaoshan.xyz/article.php?id=76
