热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

我移动地图时搜索

如何解决《我移动地图时搜索》经验,为你挑选了1个好方法。

我在许多城市组织了我的数据库中的完整地址.我使用地理编码将标记放在地图上,并在页面中显示组织列表.然后我尝试使用地理定位找到用户.

我的问题是如何在用户位置附近显示组织,并在用户移动地图时自动更新组织列表(当我说移动地图时我的意思是像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 


推荐阅读
author-avatar
死性不改2502857027
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有