嗨,我有一个网络应用程序,其中 php 从 mysql db 获得的结果包括谷歌地图 api 的坐标。以下是我在 php 上的代码
$businessMapper = new Application_Model_Mapper_BusinessMapper();
$biz = $businessMapper->searchBusinessByCityAndName($searchtext,$city);
$this->view->biz = $biz;
结果数组如下:
[0] => Array
(
[business_name] => Madam Kwan's Restaurant KLCC
[business_url] => Madam-Kwan-s-Restaurant-KLCC
[reviews_num] => 2
[business_id] => 134
[rating] => 3
[business_phone] => 03-2026 2297
[business_add1] => Suria Klcc
[business_add2] => Jalan Ampang
[x] => 101.74357729999997
[y] => 3.1597723
[photo_url] => 201302051423582
[cat_name] => Restaurants
)
[1] => Array
(
[business_name] => Spring Garden Restaurant
[business_url] => Spring-Garden-Restaurant
[reviews_num] => 2
[business_id] => 135
[rating] => 4
[business_phone] => 03-2166 9881
[business_add1] => Lot 413-414, Level 4
[business_add2] => Kuala Lumpur City Centre
[x] => 101.71465799999999
[y] => 3.1567893
[photo_url] => 201302011217282
[cat_name] => Restaurants
)
[2] => Array
(
[business_name] => Hard Rock's Cafe Kuala Lumpur
[business_url] => Hard-Rock-s-Cafe-Kuala-Lumpur
[reviews_num] => 1
[business_id] => 137
[rating] => 2
[business_phone] => 03-2715 5555
[business_add1] => Ground Floor, Wisma Concorde
[business_add2] => Jalan Sultan Ismail
[x] => 101.70525199999997
[y] => 3.155552
[photo_url] => 201302011203172
[cat_name] => Restaurants
)
[3] => Array
(
[business_name] => Sao Nam
[business_url] => Sao-Nam
[reviews_num] => 1
[business_id] => 141
[rating] => 4
[business_phone] => 03-2144 1225
[business_add1] => Anggun Boutique Hotel 7 & 9
[business_add2] => Tengkat Tong Shin
[x] => 101.70798279999997
[y] => 3.1463384
[photo_url] => 201302011122322
[cat_name] => Restaurants
)
[4] => Array
(
[business_name] => Palate Palette
[business_url] => Palate-Palette
[reviews_num] => 1
[business_id] => 150
[rating] => 3
[business_phone] => 03-2142 2148
[business_add1] => 21 Jalan Mesui
[business_add2] =>
[x] => 101.70791299999996
[y] => 3.149042
[photo_url] => 201302011031132
[cat_name] => Restaurants
)
x 和 y 值用于在 google map api 上映射地图。在视图模板中,谷歌地图 api javascripts 如下:
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
<script type="text/javascript">
var locations = [
{business_name1},{x1},{y1}
{business_name2},{x2},{y2}
etc...
];
var map = new google.maps.Map(document.getElementById('map-container'), {
zoom: 10,
center: new google.maps.LatLng(-33.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
现在的问题是,我如何将结果数组从 php 传递到 javascripts,以便它可以遍历 x、y 和企业名称并绘制地图?