Best way to geocode Ukraine postcode with Google Maps API? - google-maps

What is the most effective and accurate way to geocode a Ukraine postcode? Using the built in geocode object results in massively blurred results (lots of postcodes returning just a general area).
Are there any free Ukraine postcode geocoding services I can plug into via JavaScript?

If I´ve understand your Question correct, you could simply set a componentRestrictions. Could look like this:
doGeocode: function (address, postal_code, callback) {
console.log("TEST: " + address.toString());
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address': address,
'componentRestrictions': {
'postalCode': postal_code,
'country': 'de' //change this to the Code of Ukraine
}
}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
console.log(results);
callback(results);
} else {
//Error handling
alert('Geocode was not successful for the following reason: ' + status);
}
});
Note: Of course you have to set the country code for Ukraine here. And, because you didn´t mentioned which information you have either address or lat/lng, I just gave you an example for addresses.

Related

different results between map.google.com and google api for javascript

i'm making simple website that helps to find direction between 2 points.
and i found something strange.
if i search through map.google.com it returns exact results, but mine dose not.
for example, i set "New York University, New York, NY, United States" as origin and "260 Broadway New York NY 10007" as destination using map.google.com
using map.google.com
if i use my website using googleMap API->
using api
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDs8SYxRh-pMXa9Qe-K1nVY0g3CLpmJ9mo&signed_in=true&libraries=places&callback=initMap" async defer></script>
function calculateAndDisplayRoute(directionsDisplay, directionsService,
markerArray, stepDisplay, map) {
for (var i = 0; i < markerArray.length; i++) {
markerArray[i].setMap(null);
}
directionsDisplay.setPanel(document.getElementById('panel'));
var selectedMode = document.getElementById('mode').value;
directionsService.route({
origin: document.getElementById('pac-input').value,
destination: document.getElementById('pac-input2').value,
travelMode: google.maps.TravelMode[selectedMode]
}, function(response, status) {
// Route the directions and pass the response to a function to create
// markers for each step.
if (status === google.maps.DirectionsStatus.OK) {
document.getElementById('warnings-panel').innerHTML =
'<b>' + response.routes[0].warnings + '</b>';
directionsDisplay.setDirections(response);
//showSteps(response, markerArray, stepDisplay, map);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
It looks like you have places autocomplete inputs and read value of these inputs in your code.
I can suggest using the place ID from places autocomplete in your directions service. This way you will be sure that you work with the address that was chosen.
Look at this example and type there your addresses http://jsbin.com/xuyisem/1/edit?html,output

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

Google Maps Autocomplete API X Geocoder

I'm trying to use Google Maps Autocomplete API but there is some discrepancies between it and Geocoder API, for example:
On the autocomplete API, I'm trying to search the address "Rua Tiradentes, 1020, Ibirubá", when I select on the list, the address component "street_number" doesn't come, it's an issue with this and other addresses.
Let's try with geocoder API:
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': 'Rua Tiradentes, 1020, Ibirubá' }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results);
} else {
alert("Geocoder failed due to: " + status);
}
});
Now, the street_number is inside the address_components, is there any workaround or Google Autocomplete isn't reliable?
Here is the places code:
var b = new google.maps.places.Autocomplete(myInput);
google.maps.event.addListener(b, 'place_changed', function () {
console.log(b.getPlace());
})
The possible workaround is the following. You can try to geocode the place to get all address components. Recently, Google added possibility to geocode addresses using the placeId as a request parameter.
You can find more detailed information in the documentation:
https://developers.google.com/maps/documentation/javascript/geocoding
https://developers.google.com/maps/documentation/javascript/3.exp/reference#GeocoderRequest
So, you can get the place like var place = autocomplete.getPlace(); you can obtain the place ID like place.place_id and execute geocoding request like this one:
geocoder.geocode( { 'placeId': place.place_id}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});

how to add or show zip code boundary Google maps v3

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.

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().