私は約4000のアドレスのデータベースを持っていますが、私はGoogleマップ上にマーカーとしてリストしたいと思います...私の最終目標は、2種類のマーカー今のところ私はマップのjavascriptの場所の変数に私のPHPからの結果を結合する方法を知っていると思います。ここで成功した緯度とlogitudeをエコー表示PHP ...ここデータベースクエリからGoogleマップマーカーを作成する
$address = pg_query($conn, "
SELECT
incident.address,
incident.city,
incident.state_1
FROM
fpscdb001_ws_001.incident
WHERE
incident.initial_symptom = 'Chrome Upgrade' AND
incident.is_installed != 'true';");
if (!$address) {
echo "Query failed\n";
exit;
}
while ($markers = pg_fetch_row($address)){
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$markers[0]."&sensor=true";
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->status;
if ($status=="OK") {
$Lat = $xml->result->geometry->location->lat;
$Lon = $xml->result->geometry->location->lng;
$LatLng = "$Lat,$Lon";
}
echo "<td>$LatLng</td>";
}
ではJavaScriptされている...サンプルコードでは、緯度とLNG列挙されている、私はPHPを実行する必要があるところ、これがあると仮定します。
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: {lat: 39.350033, lng: -94.6500523}
});
// Do not actually need labels for our purposes, but the site_id is best if they are required.
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
// Add some markers to the map.
// Note: The code uses the JavaScript Array.prototype.map() method to
// create an array of markers based on a given "locations" array.
// The map() method here has nothing to do with the Google Maps API.
var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
label: labels[i % labels.length]
});
});
// Find a way to set lat and lng locations from database.
var markerCluster = new MarkerClusterer(map, markers,
{imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}
var locations = //some code to populate from database
私はAPIキーを持っており、クラスタリングのJavaScriptを含んでいます。
おそらくPHPスクリプトを変更して、HTML要素の代わりにJSON形式のStringを返すようにしてください。その後、AJAXの使い方を見てください – Titus
4000のマーカーを同時に表示しようとすると、パフォーマンスに注意する必要があります。それらをフィルタリングする方法を見つける必要があります。 –