簡體   English   中英

如何在傳單地圖上繪制標記

[英]How to Plot Markers on leaflet map

在此處輸入圖片說明 我能夠以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)
            }

最簡單的方法是有一個循環遍歷標記並將其添加到地圖的循環

一個有效的示例在這里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();
    }
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM