如何解决单张边框无效
因此,我试图将传单地图上的fitBounds调整为所需的geoJson特征。首先,我从导航器的getCurrentPosition()方法返回纬度和经度,以使用反向地理编码并获取国家/地区名称。其次,国家/地区名称用于从服务器上的geoJson文件中提取geoJson特征。然后,返回的特征是用于绘制多边形和fitBounds的,一切都在apache上工作正常。当我在托管服务上上传代码时,出现错误消息,表明边界无效。我尝试了几种方法都没有成功。
有人认为我做错了吗?与托管服务有什么关系?
// get current position
navigator.geolocation.getCurrentPosition(position => {
let lat = position.coords.latitude;
let lng = position.coords.longitude
L.marker([lat,lng]).addTo(mymap);
// get current country
$.post('PHP/reverseGeo.PHP',{
lat: lat,lng: lng
},response => {
let name = JSON.parse(response)
let country = name['address']['country']
$.post('PHP/countryList.PHP',{
countryName: country
},result => {
let decoded = JSON.parse(result)
let border = L.geoJSON(decoded).addTo(mymap)
console.log(border.getBounds())
mymap.fitBounds(border.getBounds())
$('#element1').slideDown()
...
当我将border.getBounds()登录到控制台时,它什么也不返回。在apache上,它返回正确的对象。
<?PHP
$content = file_get_contents('../vendors/countries/countries_large.geo.json');
$decoded = json_decode($content,true);
$info = '';
$name = $_REQUEST['countryName'];
foreach ($decoded['features'] as $feature) {
if ($feature['properties']['ADMIN'] == $name) {
$info = $feature;
break;
} else {
$info = 'Not supported';
}
}
echo json_encode($info);
解决方法
在开发人员工具的“网络”选项卡中检查了请求的响应之后,问题是在php代码中打开的文件不在服务器上。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。