gpt4 book ai didi

javascript - 如何在传单 map 上绘制标记

转载 作者:行者123 更新时间:2023-12-03 06:12:17 25 4
gpt4 key购买 nike

enter image description here我能够以 json 格式从数据库中获取数据,目前我可以在控制台中看到数据,所以我的问题是如何绘制使用此 ajax 调用检索到的经纬度的标记。

我如何获得函数成功的标记

$(document).ready(function () {

$(function () {
var pData1 = [];
var jsonData = JSON.stringify({ pData1: pData1 });
// var jsonArray = JSON.parse(JSON.stringify(jsonData));
$.ajax({
type: "POST",
url: "map.aspx/getCityPopulation2",
data: jsonData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,

});
function OnSuccess(response) {
console.log(response.d)
}

最佳答案

最简单的方法是使用一个循环来迭代标记并将它们添加到 map

这里有一个工作示例 http://codepen.io/hkadyanji/pen/BLyYYY

//select the div that holds the map object
var mymap = document.querySelector("#map")

// ... initialize the leaflet map as expected -> such as adding a tile layer

//a function to add the markers to the map
//you will call this function passing the resulting array from
//the ajax call as the parameter

function addToMap(locationArray){

//iterates through the array object called from the server
[].forEach.call(locationArray, function(location){

var marker = L.marker([location.lat, location.lng]).addTo(mymap);

//you can even add a custom popup for the individual marker
//marker.bindPopup("custom pop up content goes here").openPopup();
}
}

关于javascript - 如何在传单 map 上绘制标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39268129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com