作者:死性不改2502857027 | 来源:互联网 | 2023-05-22 10:40
我在许多城市组织了我的数据库中的完整地址.我使用地理编码将标记放在地图上,并在页面中显示组织列表.然后我尝试使用地理定位找到用户.
我的问题是如何在用户位置附近显示组织,并在用户移动地图时自动更新组织列表(当我说移动地图时我的意思是像airbnb一样移动).
1> 小智..:
在Earth3DMap.com上工作期间,我回答了你的问题.
现场演示在这里.
不要忘记加载Places API.检查演示的HTML代码.
这是Javascript代码:
var map;
var infowindow;
var service;
var request;
var currentLocation;
var newLat;
var newLng;
var newCurrLocation;
var latlngArray;
var marker;
var markers;
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(48.1293954,11.556663), // Munich Germany
zoom: 15
});
getMoveData()
google.maps.event.addListener(map,'dragend',getMoveData) // All events are here https://google-developers.appspot.com/maps/documentation/Javascript/examples/full/map-events
}
function getMoveData() {
clearMarkers()
currentLocation = map.getCenter()
newCurrLocation = currentLocation.toString();
newCurrLocation = newCurrLocation.replace('(', '');
newCurrLocation = newCurrLocation.replace(')', '');
latlngArray = new Array();
latlngArray = newCurrLocation.split(",")
for (a in latlngArray) {
latlngArray[a] = parseFloat(latlngArray[a]);
}
newLat = latlngArray[0]
newLng = latlngArray[1]
map.setCenter({
lat : newLat,
lng : newLng
});
showPlaces()
}
function showPlaces(){
request = {
location: currentLocation,
radius: 500,
types: ['store'] // All types are here: https://developers.google.com/places/documentation/supported_types
};
infowindow = new google.maps.InfoWindow();
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i