I am developing web application on MVC, I have a requirement to automatically find the distance between two locations using the pin code. So, I started using the google map distance matrix API as below:
https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" + Convert.ToString(origin) + "&destinations=" + Convert.ToString(destination) + "&key='MY key'
API is working fine for pin codes of India, but I have to deploy the application on Cambodia and for Cambodia pin code the API is not working.
Can anyone help me, please?
I've had a look at your request https://maps.googleapis.com/maps/api/distancematrix/xml?origins=12413&destinations=12211&key=YOUR_API_KEY
Please note that 12413 and 12211 in origins and destinations parameters are very ambiguous values. You have to provide more precise addresses in order to get results. The Distance Matrix API will geocode the 12413 and 12211 internally.
For example, the 12413 will be geocoded to 'Cairo, NY 12413, USA' a postal code in the USA. You can see this in Geocoder tool:
https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder/#q%3D12413
The 12211 will be geocoded to 'Albany, NY 12211, USA':
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D12211
In both cases it's not a pin code in Cambodia as you expect.
Even more, when I try to find a postal code 12413 or 12211 in Cambodia using a component filtering I get ZERO_RESULTS:
https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder/#in_postal_code%3D12413%26in_country%3DKH%26options%3Dtrue
https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder/#in_postal_code%3D12211%26in_country%3DKH%26options%3Dtrue
Attempts to get postal code from reverse geocoding of coordinate in Cambodia also lead to ZERO_RESULTS:
https://maps.googleapis.com/maps/api/geocode/json?latlng=11.55486%2C104.905679&result_type=postal_code&key=MY_API_KEY
Although the locality for the same coordinate can be found:
https://maps.googleapis.com/maps/api/geocode/json?latlng=11.55486%2C104.905679&result_type=locality&key=MY_API_KEY
It's 'Phnom Penh' with place ID ChIJ42tqxz1RCTERuyW1WugOAZw.
Taking into account all these facts it looks like Google doesn't have pin code information for Cambodia in their database.
I can suggest using a place autocomplete in your application. This way the user can select a suggested address and you can use a place ID selected by user to execute distance matrix requests. Have also a look at geocoding best practices in official documentation:
https://developers.google.com/maps/documentation/geocoding/best-practices
I hope this helps!
Related
Is there a way by using azure-maps or google-maps to get from longitude and latitude all postal codes and municipalityes that are in range of X kilometers?
I've yet checked the Get Search Nearby of azure, but it returns only points of interests and it is not possible to specify in the API a range in which the data should be get.
In Azure Maps, getting all postal code/municipalities within a specified distance of a location or within an area is not currently available. However, this is something being investigated as a possible future service. Consider submitting this as a feature request here: https://feedback.azure.com/forums/909172-azure-maps
I don't believe Google Maps has any such service either.
It's hard for me to understand why Postman is returning me restaurant in US even if I'm restricting the research to postal_code:00100|country:IT (00100 = Rome zip code, IT = Italy)
This is my GET:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurant&components=postal_code:00100|country:IT&key=MYSECRETKEY
Where am I wrong?
The components filtering is not supported in Places API text search.
Take a look at official documentation, there is no components parameter available:
https://developers.google.com/places/web-service/search#TextSearchRequests
To bias your results you should use the location and radius parameters.
The components filtering is supported only in Geocoding API. So you can solve the issue in two steps.
Get position of the postal code using Geocoding API
Search restaurants using Places API text search and location from the first step
E.g.
Get location of postal code 00100
https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A00100%7Ccountry%3AIT&key=YOUR_API_KEY
Now use coordinate 41.9228369,12.5014301 to search restaurants in 5km radius
https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurant&location=41.9228369%2C12.5014301&radius=5000&key=YOUR_API_KEY
Hope this helps!
I am developing an app that displays the Distance & path between 2 distances. In this case I have used following addresses:
Source: Major Bhola Ram Enclave
Destination: Ring Road Mall, Sector 3, Rohini, New Delhi, Delhi
When I use Directions API then I get following result, see image below:
But, when I search these addresses in Google Maps then I get different Result.
Click here to see Google Maps result
I searched a lot about this but I couldn't find any reason/solution for this.
Please guid me in right direction.
Thanks.
Those are not addresses, they are places. If you want a similar result to Google Maps, you need to use the placeId or the coordinates returned for that place from the places service in the directions request.
http://www.geocodezip.com/v3_example_geo2.asp?addr1=Major%20Bhola%20Ram%20Enclave&addr2=Ring%20Road%20Mall,%20Sector%203,%20Rohini,%20New%20Delhi,%20Delhi&place=1&place=2
(uses the results from the place service)
I am using Google's reverse geocoding functionality with the maps api v3 to retrieve postal addresses for latitude longitude (when dragging a marker around a map).
This is a UK application only, and part of the system requires a full, or near full, postcode to process correctly. However the reverse geocoder regularly returns just the part of the postcode - for example "GU3", even when the actual address returned appears to be complete - for example including street and house number.
Is there anyway, preferably google but otherwise if not, of 'snapping' the address to the nearest full postcode?
I'm aware similar functionality exists for snapping to the nearest panorama view, but there appears to be no equivalent for postcode.
The UK post code database is available for download from the Ordnance Survey open data
www.ordnancesurvey.co.uk/opendata
Alternatively you can use a service like uk-postcode.com to return the closest post codes to a location
See the example at https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-reverse
Try a UK location like 51.436951, 0.058112.
The results include an address_component of postal_code, "SE9 3AG".
It may be necessary to geocode the address you're given and then reverse-geocode the results in order to get the postcode. But it is possible.
How can I extract a Postal Code or ZIP of a place by giving Google Maps a city on the map?
Basically I'm looking for a free verification service for checking completed addresses for accurate details.
I seem to remember the maps API can somehow provide a geographical point when given an address. Now I'm searching for a slightly reversed situation in order to validate the postal code typed in with a city.
You need to Geocode the address to get best match coordinates
and then Reverse Geocode the coordinates to compare zip.