私は geojson についてたくさん読んだことがありますが、別の方法があるかどうか疑問に思っています。以下は、現在の関心のあるポイントを追加する方法です。
var map = L.map('map').setView([39.76, -98.5], 4);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(map);
var marker = L.marker([33.1958, -117.3786]).addTo(map);
marker.bindPopup("<b>Trainers</b><br>Oceanside, CA.").openPopup();
var marker = L.marker([38.9125, -75.4283]).addTo(map);
marker.bindPopup("<b>Trainers</b><br>Milford, DE.").openPopup();
var marker = L.marker([41.26129, -95.93262]).addTo(map);
marker.bindPopup("<b>Trainers</b><br>Omaha, NE.").openPopup();
var marker = L.marker([25.77516, -80.2002]).addTo(map);
marker.bindPopup("<b>Trainers</b><br>Miami, FL.").openPopup();
//map.on('moveend', onMapMove);
//On mouse over will display the coordinates
map.on('mousemove', function (e) {
var latlng = e.latlng;
document.getElementById('latlong').innerHTML = latlng;},
this);
これが私のajaxです:
$(document).ready(function(){
$.ajax({
type: 'POST',
dataType: "json",
url: '<?php echo matry::base_to('tests/map_it');?>',
success: function (data)
{
alert($.parseJSON(data[0]).id);
$('#alerts').html(data);
data[0].id
}
});
});
これが私のphpです:
$mapit = sql::results("Select * from event.ACS.trainer where inactive is null or inactive=0");
foreach ($mapit as $row)
{
$return[] = json_encode($row, JSON_FORCE_OBJECT);
}
echo json_encode($return);
私のjsonオブジェクトは、必要なすべての正しいデータを返しています. 私は現在、関心のあるポイントを彼らの JavaScript ライブラリに実装することに固執しています。
これが私のjson出力です:
"{"id":19385,"first":"KIRLY","last":"MAELLI","trainer_address1":"19 NE 111TH COT","trainer_address2":null,"CITY":"MIMI","STATE":"FL","trainer_zip":"379","trainer_phone":"(-6490","trainer_fax":null,"trainer_cell":"(-6490","website_trainer_id":115,"trainer_email":"MOBA@YAHOO.COM","trainer_group":"","inactive":null}",
"{"id":19386,"first":"CHY","last":"MEH","trainer_address1":"1014 ROAD","trainer_address2":null,"CITY":"MIORD","STATE":"DE","trainer_zip":"63","trainer_phone":"","trainer_fax":null,"trainer_cell":"(-8811","website_trainer_id":118,"trainer_email":"CAH@AOL.COM","trainer_group":"","inactive":null}",