我不想使用緯度和經度顯示多個標記,只能通過存儲在mysql數據庫中的地址顯示。緯度和經度不是表格中的商店。如何使用google map api通過地址顯示多個位置標記?
我已經在它的工作,併成功地顯示一個標誌,但我的web應用程序要求我根據位置 這裏顯示多個標記的代碼:
<?php include_once("dbcon.php") ;
?>
<html>
<?php
$search = $_POST['search'];
$results = mysql_query("SELECT * FROM eventsTable WHERE eventLocation LIKE '%$search%'");
while ($row = mysql_fetch_assoc($results)) {
$ename = $row["eventName"];
$edate = $row["eventDate"];
$edetail=$row["eventDetails"];
$eloc = $row["eventLocation"];
$ecity = $row["eventCity"];
echo "<p> ".json_encode($eloc)."</p>"; echo json_encode($ecity); }
?>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
var address = "<?php echo $eloc; ?>,<?php echo $ecity; ?>, PK";
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(30.51687, 69.40949);
var myOptions = {
zoom: 10,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
if (geocoder) {
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
var infowindow = new google.maps.InfoWindow(
{ content: '<b>'+address+'</b>',
size: new google.maps.Size(150,50)
});
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title:address
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
} else {
alert("No results found");
}
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map_canvas" style= "right-padding=0px; width:50%; height:50%">
</body>
</html>
請[停止使用'mysql_ *'函數](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。他們不再被維護,並[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。瞭解[準備的陳述](http://en.wikipedia.org/wiki/Prepared_statement),並考慮使用PDO,[它不像你想象的那麼難](http://jayblanchard.net/demystifying_php_pdo.html) 。 –
有多少「更多標記」?地理編碼器將工作約10而不會觸及查詢/速率限制。 – geocodezip
差不多40-50。 :/ – ayleen