这是一个示例,说明如何使用地址解析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);});


