我需要帮助进行作业,我试图使api jcdecaux中的标记从传单上显示在我的地图上,但是它不起作用我不知道我在做什么错,您能帮我吗?
我的javascript代码station.js获取api:
function Station () {
this.stations = [];
this.getAllStations = function () {
var bookedStation = sessionStorage.getItem('bookedStation');
ajax.get("https://api.jcdecaux.com/vls/v1/stations?contract={brisbane}&apiKey={7042c878507ac81a3c944a451f00ca5c58273ad9}", function (reponse) {
// Tab JavaScript
this.stations = JSON.parse(reponse);
//get the stations
this.stations.forEach(function(station){
if (bookedStation != null) {
bookedStation = JSON.parse(sessionStorage.getItem('bookedStation'))
}
else {
bookedStation = null
}
//reservertion from the api
if (bookedStation != null && bookedStation.number == station.number && bookedStation.available_bikes < station.available_bikes) {
station.available_bikes = bookedStation.available_bikes;
}
//create marker to the function create marker in map.js
map.createMarker(station)
})
}.bind(this));
}
}
这是我的另一张javascript地图map.js文件
window.onload = function () {
var mymap = L.map('mapid').setView([-27.461354, 153.025396], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoiaWNlc29uIiwiYSI6ImNqdXY5Y3FldTBpaDI0M25vN2t6c2M1eWcifQ.zxyUnGVSoW-9n8QozdYufg'
}).addTo(mymap);
this.createMarker = function(station) {
var marker = new L.marker([lat,lon],{}).addTo(map);
};
};