how to add or show zip code boundary Google maps v3 - google-maps

After searching zip code through geocoder i want to show boundary around that zip code region as shown in google maps. i have search 02201 as example in maps.google.com and it shows boundary around the whole zip region which indicates all the area under that zip range. here is my code which search zipcode using geocoder and i want to add boundary around that zip region.that i want to implement. please provide any solution. please see this link for image http://i46.tinypic.com/beyerq.jpg
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.fitBounds(results[0].geometry.viewport);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}

Sounds like you are trying to do something like this, but with a query to show only the specified zip code polygon. Like this similar post or this one.

Related

google maps api can't find one specific address

I am using google maps api and it works for all but one specific address. It's "99p Stores 19-20 Market Place Wisbech PE13 1DZ". When using google maps I can find it, but using js api it says 'zero results'.
My code:
function mapsSetMark(map, address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
map.setZoom(13);
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
console.log('Geocode was not successful for the following reason: ' + status);
}
});
}
"99p Stores 19-20 Market Place Wisbech PE13 1DZ" is a place not a postal address. The Geocoder is specifically for postal addresses
It can find "19-20 Market Place Wisbech PE13 1DZ"
To find "99p Stores 19-20 Market Place Wisbech PE13 1DZ" use the Places API Library

How to get the name of the region where the marker is placed in Google Maps API, gmaps.js?

i should get name of region by coordinates using Google Maps Api or gmaps.js
If you know how do it, please give me answer. And sorry for my english.
You need to use the Geocoder service to get location details from coordinates. The response from the Geocoder will contain all the details. All you need is to find out the details you are interested in.
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
'latLng': latLng
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results);
}
});
See this also http://jsfiddle.net/eB2RX/1/

Google Maps v3, reverse Geocoding and multiple Infowindow

I'm working on a google map v3.
On this map I want display several markers each one with its Infowindow where shows some information about that point.
The source of information is an javascript array with some data for each point, and up here everything works fine.
The array contains (SOMETIMES) the address (sometimes null) and ALWAYS lat-long coordinates, so when the address isn't present I have to make a reverse-geocoding. Here my code:
var geocoder = new google.maps.Geocoder();
for(var i=0;i<markersArray.length;i++){
var la=markersArray[i][0]);
var lo=markersArray[i][1]);
gpoint=new google.maps.LatLng( la,lo);
var aMarker = new MarkerWithLabel({ //part of Google Maps Utility Lib
position: gpoint,
map: map,
labelContent: deviceID,
labelAnchor: new google.maps.Point(22, 0),
labelClass: "labelStyle",
html: "<ul><li>Speed: "+markersArray[i][3]+"</li></ul>",
address: markersArray[i][4]
});
if (aMarker.address<="" || aMarker.address==null) {
geocoder.geocode({'latLng': gpoint}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
aMarker.address=results[1].formatted_address;
}
}
});
}
google.maps.event.addListener(aMarker, 'click', function () {
infowindow.setContent(this.html+" "+this.address);
infowindow.open(map, this);
});
....
}
Almost everything is ok: the markers are in position and all them show the right infowindow with the right addresses except those where the addresses were empty and were reverse-geocoding.
For this last set only the last one marker infowindow shows the right address, all other infowindow addresses's are empty.
Any idea?
Very thanks!
One way to fix this is to create a function which does the reverse geocoding and can have function closure on the infowindow and the marker.
As the reverse geocode operation is asynchronous, the returned address isn't available for any except the last marker.

How to geocode an address into lat/long with Google maps

I want to be able to plot several companies on a google map and understand I need to geocode these.
I also have the code below that plot's multiple markers on a map.
How can I Geocode several company addresses (using the following address as the first example) and incorporate it into the current code I have?
I really need someone's help as I can't make sense of the Google documentation as well as incorporating it with what I already have.
you could use google's geocoding to obtain coordinates of your post codes
EDIT: I don't really like you changing the sense of the question like that but ok. Please try sth like that (its not tested):
// Creating an array that will contain the coordinates
// for New York, San Francisco, and Seattle
var places = [];
// Adding a LatLng object for each city
//places.push(new google.maps.LatLng(40.756, -73.986));
//places.push(new google.maps.LatLng(37.775, -122.419));
//places.push(new google.maps.LatLng(47.620, -122.347));
//places.push(new google.maps.LatLng(-22.933, -43.184));
var result;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://maps.googleapis.com/maps/api/geocode/json?address=your+code&sensor=false",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
result = eval('(' + xmlhttp.responseText + ')');
if (result.status == "OK") {
var location = new google.maps.LatLng(result.results[0].geometry.location.lat, result.results[0].geometry.location.lng);
places.push(location);
this should probably work, despite possible minor errors.
EDIT2: I have just now found simpler solution:
// Creating an array that will contain the coordinates
// for New York, San Francisco, and Seattle
var places = [];
// Adding a LatLng object for each city
//places.push(new google.maps.LatLng(40.756, -73.986));
//places.push(new google.maps.LatLng(37.775, -122.419));
//places.push(new google.maps.LatLng(47.620, -122.347));
//places.push(new google.maps.LatLng(-22.933, -43.184));
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': "your+code"}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
//var marker = new google.maps.Marker({
//map: map,
//position: results[0].geometry.location
//});
places.push(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});

Google maps api v3 geocoder viewport

when I enter a location (city or country) and an infowindow is open the following code will only find locations within the area of the open infowindow:
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.fitBounds(results[0].geometry.viewport);
} else {
alert("Sorry, we couldn't find the location for the following reason: " + status);
}
});
}
I want to zoom to the location viewport WITHOUT the fitBounds
This kind of works:
map.setZoom(13);
But I don't want to specify the zoom level
Here's a link from the latter code: http://www.hostelbars.com/map_test_v3_3.html
I'd appreciate some help - thanks!
Perhaps you want to constrain the geocoding to the bounds of the visible map, rather than the open infowindow?
You need to tell the geocoder about your desired bounds in the request not when handling the result.
Refer to http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest
Set the bounds in the geocoderRequest to map.getBounds().