栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Google Maps-查找给定半径内的所有标记Javascript / Php

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Google Maps-查找给定半径内的所有标记Javascript / Php

这是一个示例,说明如何使用地址解析API和一些简单的几何图形来解决此问题。

(请注意,为简洁起见,我已经硬编码了地址和半径。)

// we assume that you have an array of markersvar markers = [];//In order to lookup the the position of a zip-pre you can use the geocoding API:// https://developers.google.com/maps/documentation/geocoding/var geopre_api_base_url = "http://maps.googleapis.com/maps/api/geopre/json?";var params = {    adress : 05673,    components : "country:us",    sensor : false}// This is the result set of markers in areavar in_area = [];//  http://maps.googleapis.com/maps/api/geopre/json?address=05673&components=country:US&sensor=false$.getJSON( geopre_api_base_url + $.param(params), function(data) {    var location, search_area, in_area = [];    location = data['results'][0]['address_components']['geometry']['location'];    // We create a circle to look within:    search_area = {        strokeColor: '#FF0000',        strokeOpacity: 0.8,        strokeWeight: 2,        center : new google.maps.LatLng(location.lat, location.lon),        radius : 500    }    search_area = new google.maps.Circle(search_area);    $.each(markers, function(i,marker) {       if (google.maps.geometry.poly.containsLocation(marker.getPosition(), search_area)) {         in_area.push(marker);       }    });    console.info(in_area);});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/413461.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号