如何从数组中获取坐标并将它们放入传单地图上的标记中?这是我的代码:
<div id="map">
<script>
var map = L.map('map').setView([39.76, -98.5], 4);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(map);
$(document).ready(function(){
$.ajax({
type: 'POST',
dataType: "json",
url: '<?php echo matry::base_to('tests/map_it');?>',
success: function (data)
{
//alert (data[0].first + " " + data[0].last + " " + data[0].trainer_address1 + ", " + data[0].CITY + " " + data[0].STATE);
for (var i=0;i<data.length;i++)
{
document.write(data[i].first + ' ' + data[i].last + " " + data[i].trainer_address1 + ", " + data[i].CITY + " " + data[i].STATE + '<br />');
}
}
});
});
</script>
<?php
spl_autoload_register('autoload_lib');
// $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);
header('Content-Type: application/json');
$mapit = sql::results("Select * from event.ACS.trainer where inactive is null or inactive=0");
foreach ($mapit as $row)
{
$return[] = $row;
}
//echo json_encode($return);
$array = array(array('addr1'=>'$data', 'city'=>'Carlsbad', 'state'=>'CA'),array('addr1'=>'42 Mer Gn', 'city'=>'dido', 'state'=>'CA'));
foreach ($array as $addr)
{
$mapit = new MapIt($addr);
print_r($mapit->send_request());
}
这是最后一步,但我无法弄清楚。Leaflet 接受坐标而不是地址,所以我已经将地址转换为坐标。希望对这个问题提供一些指导。谢谢你。
Array
(
[lat] => 33.158099
[lng] => -117.349701
)
Array
(
[lat] => 33.119202
[lng] => -117.085602
)