我试图在发送纬度和经度坐标后从OSM服务器获取道路的最大速度限制值。我已经完成了代码,但加载它们似乎有问题。我不明白是什么问题。下面给出的是php代码:
<?php
//$lat = isset($_GET['lat']) ? floatval($_GET['lat']) : "";
//$lng = isset($_GET['lng']) ? floatval($_GET['lng']) : "";
$lat = 24.192163;
$lng = 55.649185;
$latm = -0.00015 + $lat;
//$latm = 24.229544; //s
echo $latm. "\n";
$lngm = -0.00015 + $lng;
//$lngm = 55.775513; //w
echo $lngm. "\n";
$latp = 0.00015 + $lat;
//$latp = 24.229844; //n
echo $latp. "\n";
$lngp = 0.00015 + $lng;
//$lngp = 55.775813; //e
echo $lngp;
$json_url = 'http://overpass.osm.rambler.ru/cgi/interpreter';
$data = '<query type="way"> <bbox-query s="' . $latm . '" w="' . $lngm . '" n="' . $latp . '" e="' . $lngp . '"/> <!--this is auto-completed with the current map view coordinates.--> </query> <print/>';
$ch = curl_init( $json_url );
$options = array(
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true,
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$xml = simplexml_load_string($result);
foreach ($xml->way as $i) {
foreach ($i->tag as $tag) {
if ($tag['k'] == "maxspeed") {
$maxspeed = $tag['v'];
break;
}
}
}
$response["speedlimit"] = "$maxspeed";
echo json_encode($response);
?>
出于测试目的,我已经设置了特定区域的$ lat和$ lng坐标以获得速度限制。但是,它没有用。
我希望有人能引导我走向正确的方向。非常感谢...