简体   繁体   English

无法将标记加载到LeafLet中

[英]Unable to Load Markers into LeafLet

I read this example from LeanPub where I learned to get coordinates for Bus Stops. 从LeanPub阅读了此示例,并该示例中学习了获取公交车站的坐标。 I followed the steps & was able to successfully get the Coordinates from BusStops.php as follow 我按照以下步骤操作,并能够按照以下步骤从BusStops.php成功获取坐标

var BusStopsCordinates = [[-40.994970,174.508080],[-41.302690,173.636960],[-41.494130,173.542100],[-40.985850,174.506590],[-40.931630,173.817260],[-41.518300,174.780810],[-41.420790,173.578300],[-42.084140,173.966320],[-41.512850,173.532740]];

Following the steps. 遵循步骤。 I called this BusStops.php file into javascript on my Index.html page as follows. 我将这个BusStops.php文件调用到我的Index.html页面上的javascript中,如下所示。

<script>
<?php include 'busstops.php'; ?>
    var map = L.map('map').setView([-40.994970, 174.508080], 18);
    mapLink = 
        '<a href="http://openstreetmap.org">OpenStreetMap</a>';
    L.tileLayer(
        'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; ' + mapLink + ' Contributors',
        maxZoom: 18,
        }).addTo(map);

    for (var i = 0; i < planes.length; i++) {
        marker = new L.marker([planes[i][0],planes[i][1]])
            .addTo(map);
    }        
</script>

According to the exmple i should get result like this. 根据示例,我应该得到这样的结果。 在此处输入图片说明

but i am getting no result at all. 但是我什么都没有。 I am new to PHP & Leaflet. 我是PHP和Leaflet的新手。 Please tell me where is the main problem. 请告诉我主要问题在哪里。

It seems to me that you just forgot to replace the planes variable from the example by your BusStopsCordinates variable? 在我看来,你只是忘了更换planes由你来自例如可变BusStopsCordinates变量?

Demo: http://jsfiddle.net/ve2huzxw/28/ 演示: http//jsfiddle.net/ve2huzxw/28/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM