【发布时间】:2014-02-02 07:55:49
【问题描述】:
这就是我所拥有的... PHP 从 API url 中提取了 10 对纬度/经度,我已经设法让它正常工作,但我似乎无法将它们绘制在带有多个标记为 1-10 的地图上。
我的php代码:
<?php
// Loading Domus API
$url_search = 'http://url/site/go/api/search';
$xml_search = @simplexml_load_file($url_search) or die ("no file loaded") ;
//Displaying latitude and longutude
$house = json_encode($house);
}; ?>
JavaScript 位:
var locations = "<?php foreach($xml_search->property as $house) { echo $lat = $house->address->latitude , $long = $house->address->longitude;}; ?>";
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(37.0625,-95.677068),
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));
}
这里需要显示的内容
<div id="map" style="width: 500px; height: 400px"></div>
当然,我只是得到一个空白页。
【问题讨论】:
-
您是否遇到任何 JS 错误?您是否正确加载了 Google Maps API JS?你怎么称呼上面的JS;它是内联的,还是在你正在调用的函数中;如果是,怎么做?
-
不,我没有收到任何错误 - 只是一个空白页。我其实对 JS 了解不多。
-
那么上面的所有javascript都应该在一个函数中。这应该在窗口加载时调用,参见developers.google.com/maps/documentation/javascript/…
-
我遇到的问题是将 lat/long 从 php 解析为 javascript...
-
你怎么知道的?如果是这样,请尝试使用
parseFloat(locations[i][1])等
标签: javascript php api google-maps google-maps-api-3