Geocoding with REST API gives different results from Here WeGo online map - here-api

I'm a student working on a navigation project using Here's REST APIs.
The question I'm asking pertains to discrepancies when searching for a location using the Geocoder REST API and the Here WeGo online map.
I am trying to perform forward geocoding using the search term "Kent Ridge MRT" via the Geocoder API to get the corresponding set of coordinates. This is a subway station located on my campus, which the National University of Singapore.
The following parameters are used
destination_input = "Kent Ridge MRT singapore"
country = "SGP"
gen = 9
These are placed in a dict called geocoding_params
geocoding_params = {"app_code": app_code, "app_id": app_id, "searchtext": destination_input,
"country": country, "gen": gen}
A GET request is then made using the requests library in Python 3.7.3, via
geocoding_data = requests.get(url = geocoding_base_url, params = geocoding_params)
Where geocoding_base_url = "https://geocoder.api.here.com/6.2/geocode.json"
The request gives me three possible locations, listed here in Lat/Lon: (1.30098, 103.77231), (1.29354, 103.77138) & (1.2935, 103.78102).
None of these are the actual coordinates of Kent Ridge MRT station (1.29364, 103.78466), which can be obtained when one types the exact same search terms using Here WeGo.
I am curious to know why such a difference exists and whether there is a way to get what I see in Here WeGo.
What I have tried as of now includes broadening the search field by removing country and gen parameters while keeping searchtext = "Kent Ridge MRT singapore", but to no avail. The results match the three I have gotten above.

The SearchAPI powering HereWeGo and GeocoderAPI are different services with different approaches and goals. The reason why you are not finding your place "Kent Ridge MRT"with GeocoderAPI is because GeocoderAPI does not support places.
The good news: both are unified as OpenSearch in the HERE Open Location Platform:
https://developer.here.com/products/open-location-platform
Check the Open Location Platform documentation at
https://openlocation.here.com/resources/documentation

Related

Empty Results from Here API for the sample zipcodes

When I do the GET Request to the here API with the below zip codes I am getting an empty list. But When I google these zip codes, I can see that they are valid.
Here is the GET Request URL: https://geocode.search.hereapi.com/v1/geocode?qq=postalCode=[Insert-zip-code];country=USA&apiKey=[Insert-API-Key]
Below are the fallowing Zip Codes:
75046
34988
68902
45258
19486
88102
32245
28603
68501
93403
68602
91365
Try with https://geocode.search.hereapi.com/v1/geocode?q=postalCode=zip_code+USA&apiKey=your_api_key
Notice that there is only one q.
The above will work, but in some cases it will give you results not only from the United States.
Keep in mind what the API documentation says for this service:
Address lookup by postal code (SGP, IRL)
(...) This feature is available for these two countries only.
It's only for Ireland and Singapore.
There is an alternative for the United States (and Netherlands), but it requires the zip+4 code.
What is a Zip+4 Code?
A ZIP+4 code uses the basic five-digit code plus four additional
digits to identify a geographic segment within the five-digit delivery
area, such as a city block, a group of apartments, an individual
high-volume receiver of mail, a post office box, or a specific
delivery route
Example: https://geocode.search.hereapi.com/v1/geocode?qq=postalCode=60606-1506&apiKey=your_api_key
Notice that there are two q's.

HERE Geocode Autocomplete no Unit/Apt No

I am not getting the Unit Number in response structure as mentioned in the API Documentation,
"For addresses from Australia, New Zealand and Canada a unit number can be included in the result if it was part of the query."
I am using autocomplete geocoder for NZ.
I tried to change the requestType but no help. API is not so clear on how to request Unit Number.
Got it. Actually, when we type the unit/housenumber in the query it actully brings the Unit number.

Geocoding addresses with googleway: incoherent results

I am trying to geocode addresses on Google Maps using the google_geocode function from the package googleway in R. I am using a key obtained from Google that allows me to go over the 2500/day limit (and being charged for that). I have different types of problems, mainly due to the way the addresses I use are written, but there is one issue that I would like to ask here: how is it possible that I sometimes get no results querying with googe_geocode, but if I type the same address string on http://www.google.com/maps/ it does return a result?
My example:
address="AVENDAÑO, 30-32 VITORIA-GASTEIZ 01008, ES"
# the address I want to geocode. Its format is "street, number, city postcode, country" in a single string.
google_geocode(address=address,key=mykey) # I write the right key as mykey.
# I get no results:
$results
list()
$status
[1] "ZERO_RESULTS"
But, if search for exactly the same address string in Google Maps, I get the right location (showing that this is Abendaño Kalea in Vitoria, Spain):
https://www.google.com/maps/place/Abenda%C3%B1o+Kalea,+30,+01008+Vitoria-Gasteiz,+Araba/#42.8451894,-2.6855022,17z/data=!3m1!4b1!4m5!3m4!1s0xd4fc213d775d83d:0xc2a5f2ffa8721c2a!8m2!3d42.8451855!4d-2.6833135
Can anyone explain what may be going on? Maybe some staff from Google Maps or Google Geocoding API may help?
Thanks a lot,
Note that Google knows this street as 'ABENDAÑO, 30-32 VITORIA-GASTEIZ 01008, ES', so the B and V letters are important. I know that in Spanish language this is the same sound, but probably Google expects exact match.
According to the documentation:
Specify addresses in accordance with the format used by the national postal service of the country concerned.
source: https://developers.google.com/maps/faq#geocoder_queryformat
On the Correos.es I can see that the official street name is ABENDAÑO as shown in the following screenshot
So just use the following request to get results:
https://maps.googleapis.com/maps/api/geocode/json?address=ABENDA%C3%91O%2C%2030-32%20VITORIA-GASTEIZ%2001008%2C%20ES&key=YOUR_API_KEY
Or the same thing in geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3DABENDA%25D1O%252C%252030-32%2520VITORIA-GASTEIZ%252001008%252C%2520ES
I hope this helps!
I think it is likely that is due to encoding issues. I have had this happen when trying to geolocate addresses with "Ñ". Doing this worked for me:
string <- "AVENDAÑO, 30-32 VITORIA-GASTEIZ 01008, ES"
Encoding(string) <- "UTF-8"
google_geocode(string, key = key)
Since google changed their pricing scheme now you need to have an API key.

How to reliably get county from Google Autocomplete/Details

If I use Google Place Autocomplete for "Alpha Loft Elm" I get an address that includes only level 1 (state) in the administrative areas. But if I autocomplete for the same place using the returned formatted_address, "844 Elm St, Manchester, NH 03101, United States", I get level 2 (county) as well, with a different place-id.
I see the same behavior for other places as well. I see the same behavior from the Place Details API, when I give it the place-id returned in each case.
I need the county, and need to support autocomplete by place name.
The only workaround I've found for this is to use Place Search (textsearch) on the returned formatted_address, then use Place Details on the placeId returned for the address to get the county.
Is there a better approach?
(Also posted as a bug report on gmaps-api-issues.)
So far I am not aware of any other solution then after using Autocomplete to get the accurate address and place_id to use something like the following code to retrieve the "political" structure behind that address.
if (place.place_id) {
var service = new google.maps.places.PlacesService(map);
service.getDetails({placeId: place.place_id}, function (PlaceResult, PlacesServiceStatus) {
console.log(PlaceResult);
});
}

Correct address format to get the most accurate results from google GeoCoding API

Is there any standard format to supply the address string to Google GeoCoding API to get the most accurate results on map.
For Eg. following query not giving correct result.
http://maps.googleapis.com/maps/api/geocode/xml?address=bloom,Bloomfield,CT,06002,USA&sensor=false
Thanks
Mandeep
I believe the suggested format is:
House Number, Street Direction, Street Name, Street Suffix, City, State, Zip, Country
The results get less specific the less information you can supply, obviously.
In your sample, the geocoder is searching for a street named 'bloom', of which there are similar matches in OH instead of CT. Removing 'bloom' from the query and then searching returns Bloomfield, CT.
Definition of Google address search:
address - The street address that you want to geocode, in the format used by the national postal service of the country concerned. Additional address elements such as business names and unit, suite or floor numbers should be avoided.
https://developers.google.com/maps/documentation/geocoding/#geocoding
How should I format my geocoder queries to maximise the number of successful requests?
The geocoder is designed to map street addresses to geographical coordinates. We therefore recommend that you format geocoder requests in accordance with the following guidelines to maximise the likelihood of a successful query:
Specify addresses in accordance with the format used by the national postal service of the country concerned.
Do not specify additional address elements such as business names, unit numbers, floor numbers, or suite numbers that are not included in the address as defined by the postal service of the country concerned.
Use the street number of a premise in preference to the building name where possible.
Use street number addressing in preference to specifying cross streets where possible.
Do not provide 'hints' such as nearby landmarks.
https://developers.google.com/maps/faq#geocoder_queryformat
I found the answer incomplete and it lacked a source.
Look here: https://developers.google.com/places/documentation/autocomplete#place_autocomplete_responses
The maps autocompletion API from google returns a much simpler format: "Street address, City, Country"
Now you can use a string like that to search for an address and it should lead to one exact result.
In addition if you use the autocompletion API you will get a unique identifier too which can be used for further detail requests.
The format of the street address greatly depends on the location where you actually are.
In the US "House number, street direction, street name, street suffix" might make sense, in most of Europe it will not lead to successful query.
Addresses in most of EU are different (often "Streetname number suffix") like "Kumpelstraat 25A","Psolevcu 331/26b") and I guess we'd be surprised if we look at some eastern countries.
So if you bind your code to a single area (US, most of EU) you might be good hardcoding the format.
If you want to have a more flexible system you either need to find out propper formating for your target audience or query one of googles APIs to automatically get a proper string.
The one I linked is very good but requires an API key with a free request limit per day.
I stumbled upon this question and found a solution that worked for me:
I think the answer can be found by using component filtering, look at:
https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering
An example in Javascript:
var request = require('request');
var url = "https://maps.googleapis.com/maps/api/geocode/json?" +
"address=Herengracht 180" +
"&components=postal_code:1016 BR|country:NL" +
"&sensor=false";
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
else {
console.log('error', error);
}
});
No need to avoid apartment units. This works:
https://maps.googleapis.com/maps/api/geocode/xml?address=14202+N+42nd+St+Unit+301+33613
"Apt", "Room", and "Suite" work as well
They all return 301 as subpremise and are shown in "formatted_address" as "#301."
Paul sends...
I found that official country codes like "US", "DE", "FR" do not work well. Replacing them with the full country name gives much better results for me.
I did not find a source where that is stated.

Categories

Resources