データベースにGoogleマップの住所のリストがあり、リストから住所の1つの緯度と経度を指定したい.すべてのマーカーがこのポイントに近づくよりも.そしてマーカーはデータベースリストからのものでなければならない. .
例:緯度と経度を含む20の学校のリストがあり、学校Aに近いすべての学校のリストが必要な場合、約5 KMである可能性があります. Google マップでもピン留めされている学校。
私が持っているもの:緯度と経度を渡すと、このポイントに近いリストが表示されるスクリプトがありますが、マップにピンが表示されるのはGoogleマップであり、ピンがデータベースからのものであることを望みます.
Xampp、Wamppなどでこれを試すことができるスクリプトは次のとおりです。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Place Search</title>
<script src="https://maps.googleapis.com/maps/api/js?sensor=true&libraries=places"></script>
<style>
#map {
height: 400px;
width: 600px;
border: 1px solid #333;
margin-top: 0.6em;
}
</style>
<script>
var map;
var infowindow;
function initialize() {
var pyrmont = new google.maps.LatLng(22.716498,75.86812);//here you can pass the latitude & longitude.
map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: 500,
types: ['store']
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.search(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map"></div>
<div id="text">
</body>
</html>
私が欲しい: リストはデータベースから取得する必要があり、Google マップ API からデータベースのエントリを取得したことを覚えているので、既にピン アドレスになっているピンを作成する必要はありません。
どうすればこれを行うことができるかをお勧めします。