0
我是網絡開發新手,使用傳單和代碼時遇到問題。問題是我不能創建標記。下面是代碼:傳單無法創建標記
<html>
<head>
<link rel="stylesheet" href="<?php echo base_url();?>dist/css/leaflet.css" />
<link rel="stylesheet" href="<?php echo base_url();?>dist/css/main.css"/>
</head>
<body>
<div id="map"></div>
</body> </html>
<script src="<?php echo base_url();?>dist/js/leaflet.js"></script> <script src="<?php echo base_url();?>dist/js/jquery-1.11.0.js"></script>
<script>
var map = L.map('map').setView([51.505, -0.09], 13);
function createMarker(lat,long){
var marker = L.marker([lat,long]).addTo(map);
}
$(function(){
L.tileLayer('http://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', { attribution: '© <a href="http://osm.org/copyright" title="OpenStreetMap" target="_blank">OpenStreetMap</a> contributors | Tiles Courtesy of <a href="http://www.mapquest.com/" title="MapQuest" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png" width="16" height="16">', subdomains: ['otile1','otile2','otile3','otile4'] }).addTo(map);
$.getJSON('index.php/map/getData',function(data){
debugger;
for(i=0;i<3;i++)
{
var latitude = parseFloat(data[i].latitude);
var longitude = parseFloat(data[i].longitude);
createMarker(latitude,longitude);
}
});
}); </script>
這裏是內部的getJSON所檢索的數據:
> [
Object
hasil_uji_id: 1
latitude: 51.13
longitude: -0.07
nama_hasil_uji: "iqbal 3"
__proto__: Object
,
Object
hasil_uji_id: 123
latitude: 51.05
longitude: -0.09
nama_hasil_uji: "iqbal"
__proto__: Object
,
Object
hasil_uji_id: 1234
latitude: 51.09
longitude: -0.08
nama_hasil_uji: "iqbal 2"
__proto__: Object
]
然而,當我硬編碼的緯度和經度的值,該標記示出了。敬請賜教單張大師
'$ .getJSON'代碼部分不屬於'L.tileLayer'選項參數。但這可能不是導致您的標記不顯示的問題。你在js控制檯中收到任何錯誤消息嗎? – tyr
@tyr謝謝你的關心,我弄清楚這個問題是我自己的愚蠢:(。 –