admin管理员组文章数量:1419611
How to show google map showing the pointers for locations of multiple postal codes?
I have multiple postal codes, I want to show those postal codes with pointers in the map together.
This is example how I want this to work ()
How to show google map showing the pointers for locations of multiple postal codes?
I have multiple postal codes, I want to show those postal codes with pointers in the map together.
This is example how I want this to work (http://awesomescreenshot./0a13egtc0d)
Share Improve this question edited Aug 30, 2014 at 13:51 hennes 9,3504 gold badges45 silver badges64 bronze badges asked Aug 30, 2014 at 13:42 MariaMaria 1491 gold badge3 silver badges11 bronze badges 4- 1 Are you looking to display the area associated with each postal code as a shape on the map or do you just want to display a single marker for each postal code, located somewhere within the postal code area? – hennes Commented Aug 30, 2014 at 13:58
- I want to display area pointing with marker on th same map for all postal codes. – Maria Commented Aug 30, 2014 at 14:03
- I want to provide postal code and google map should search for it and show me map for all postal code in the same place together. – Maria Commented Aug 30, 2014 at 14:04
- How are you planning on "providing the postal codes"? The "best" solution is to geocode them offline and include the geographic coordinates. You can geocode them on page load, but if there are more than ~10, you will have to handle the API rate limit (the OVER_QUERY_LIMIT status response). – geocodezip Commented Aug 30, 2014 at 17:20
2 Answers
Reset to default 5As far as I understood you have an array of postal codes like this.
var postalCodes = [
'10405', // Berlin
...
];
You want to convert each of these ZIP codes to a marker on the map. For this purpose you can use Google's geocoding API. All you need to do is create a GeoCoder
object and call its geocode
function with the postal code and a country hint.
geocoder.geocode({
address: postalCode,
region: countryHint // e.g. 'DE' for Germany
}, function(result, status) {
// Create marker
}
A working example: JSFiddle
HTML
<div id="map-canvas"></div>
JavaScript
var postalCodes = [
'01067', // Dresden
'10405', // Berlin
'20359', // Hamburg
];
function initialize() {
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(52.5167, 12.1833),
zoom: 6
});
var geocoder = new google.maps.Geocoder();
google.maps.event.addListenerOnce(map, 'tilesloaded', function() {
for (var i = 0; i < postalCodes.length; ++i) {
geocoder.geocode({
address: postalCodes[i],
region: 'DE'
}, function(result, status) {
if (status == 'OK' && result.length > 0) {
new google.maps.Marker({
position: result[0].geometry.location,
map: map
});
}
});
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
This is the reference to use API properly.
https://developers.google./maps/documentation/javascript/examples/marker-simple
Here is the logic, you have to create multiple LatLng objects with latitudes and longitudes.
Create a map object.
Create multiple marker objects for those LatLag objects and then bind those markers to map object.
版权声明:本文标题:Google Map location with Markers according to multiple postal codes with Javascript API - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745315728a2653145.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论