我正在尝试使用Google Maps API在mySQL数据库中存储一系列城市的纬度和经度。
数组应如下所示:
var markers = [
{ lat: 45.5235, lng: -122.6762, name: "Portland" },
{ lat: 47.6062, lng: -122.3321, name: "Seattle" },
{ lat: 34.0522, lng: -118.2437, name: "Los Angeles" },
{ lat: 32.7153, lng: -117.1573, name: "San Diego" }
];
以下是我尝试实现此目的的代码:
var geocoder = new GClientGeocoder();
var markers = [
<?php
//orgnize fans by city
$query = "SELECT city, state, COUNT(*) fans FROM users GROUP BY city ORDER BY fans DESC";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
var address = echo '"'$row['city'].", ".$row['state']'"';
geocoder.getLatLng(address, function(point) {
var latitude = point.y;
var longitude = point.x;
});
echo "{ lat: \"".latitude.", lng: ".longitude.", name: "'"'.$row['city'].", ".$row['state'].'"'"},\n ";
echo "<br/>";
}
?>
];
我收到以下错误:
解析错误:语法错误,意外T_VAR
答案 0 :(得分:0)
geocoder.getLatLng(address, function(point) {
var latitude = point.y;
var longitude = point.x;
});
此代码不是PHP。很少有回声丢失。而且上面那行也很奇怪。