HERE Geocode search API is not returning the city for some german postal codes - here-api

We are using the HERE API for a looking up the city assigned to a postal code. So if we take the postal code 99947 for example, the API returns the following Address without a city. The expected city is Bad Langensalza
GET https://geocode.search.hereapi.com/v1/geocode?q=99947&apiKey=apiKey&limit=5&in=countryCode:DEU
"address": {
"label": "99947, Thüringen, Deutschland",
"countryCode": "DEU",
"countryName": "Deutschland",
"stateCode": "TH",
"state": "Thüringen",
"countyCode": "UH",
"county": "Unstrut-Hainich-Kreis",
"postalCode": "99947"
},
EDIT: Copy and paste error in response, added the correct one now
If you lookup the city Bad Langensalza you do get the postal code, so you can see that it should be working.
GET https://geocode.search.hereapi.com/v1/geocode?q=Bad%20Langensalza&apiKey=apiKey&limit=5&in=countryCode:DEU
"address": {
"label": "Bad Langensalza, Thüringen, Deutschland",
"countryCode": "DEU",
"countryName": "Deutschland",
"stateCode": "TH",
"state": "Thüringen",
"countyCode": "UH",
"county": "Unstrut-Hainich-Kreis",
"city": "Bad Langensalza",
"postalCode": "99947"
},
What is the issue that we would not get the city in the first query, but we do get it in the second query?

If we can not uniquely identify one city for a postal code then city is not returned.The next hierarchy which is State is returned. This is always like this in HLS and there are no plans to fix this behaviour in HLS.

Related

HTTP 400 response received

The following HTTP request was sent and an HTTP 400 response was received. What is wrong with the request that caused it to fail?
POST /api/v2/organizations/4523jddfgd/projects HTTP/1.1
Host: www.reddit.com
Content-Type: application/json
Authorization: Bearer VALID_API_TOKEN
[
"name": "Project 1",
"package": "Standard",
"address": {
"street": "12456 Main St",
"city": "Dallas",
"zip": "75200",
"state": "TX",
"country": "USA"
}
]
This is an interview question, can you help guys ?
Have a look at the MDN wiki page about HTML status code 400.
Status code 400 points to a client side error e.g. malformed request body. Another reason could be that a required header is missing. As indicated in the MDN wiki page you should not attempt to send the very same request unmodified again as the result will be the same as it is not a server side issue.
What you should do instead is: consult the API documentation again and make sure that no header is missing and the request body is valid (i.e. valid JSON/ XML/ whatever in the correct structure).
Looking at your request I can see that the body is not valid JSON.
[
"name": "Project 1",
"package": "Standard",
"address": {
"street": "12456 Main St",
"city": "Dallas",
"zip": "75200",
"state": "TX",
"country": "USA"
}
]
This cannot be parsed, hence the error. An array cannot hold properties. What is missing is a { and } after the [ and before the closing ].
Using the following request body should work.
[
{
"name":"Project 1",
"package":"Standard",
"address":{
"street":"12456 Main St",
"city":"Dallas",
"zip":"75200",
"state":"TX",
"country":"USA"
}
}
]
EDIT
As #Evert pointed out, it is more likely that you need to replace [] with {} as POST requests are used to create single new resources. But the only way you can be absolutely sure is by reading the API documentation.
{
"name":"Project 1",
"package":"Standard",
"address":{
"street":"12456 Main St",
"city":"Dallas",
"zip":"75200",
"state":"TX",
"country":"USA"
}
}

HERE api reverse geocoder does not output street numbers

We are using HERE api REST version 7 to reverse geocode location through a freemium plan
GET https://revgeocode.search.hereapi.com/v1/
revgeocode
?at=48.2181679%2C16.3899064
&apiKey=XXX
&lang=en
We are observing that the returned addresses never contain street numbers, making the geocoded addresses useless in the context of our app.
Are we missing something ?
The newer version of reverse geocoding (the API you shared) returns street names and not street numbers.
The old API that does not return street numbers:
https://reverse.geocoder.ls.hereapi.com/6.2/reversegeocode.json?prox=41.8842%2C-87.6388%2C250&mode=retrieveAddresses&maxresults=&&apiKey=APIKEY
New API that returns street names:
https://revgeocode.search.hereapi.com/v1/revgeocode?at=48.2181679%2C16.3899064&apiKey=APIKEY&lang=en
I tried your request and the returned response contains houseNumber within address property:
request:
https://revgeocode.search.hereapi.com/v1/revgeocode?at=48.2181679%2C16.3899064&apiKey=APIKEY&lang=en
response:
items": [
{
"title": "Heinestraße 42, 1020 Vienna, Austria",
"id": "here:af:streetsection:2VFm4oq5Zq8utAoSB90pmA:CgcIBCD6iaNNEAEaAjQy",
"resultType": "houseNumber",
"houseNumberType": "PA",
"address": {
"label": "Heinestraße 42, 1020 Vienna, Austria",
"countryCode": "AUT",
"countryName": "Austria",
"state": "Vienna",
"county": "Vienna",
"city": "Vienna",
"district": "2. Bezirk-Leopoldstadt",
"street": "Heinestraße",
"postalCode": "1020",
"houseNumber": "42"
},
...

How can I request pinpoint accurate geocoding data using HERE Api

I am looking to use HEREs geocoding service to locate the Lat and Lon of a place based on a UK postcode. At the moment my request will return a rough location even though I have provided a full postcode.
The old "geocode" API that I used previously, would return relevant results however this has been put into maintenance and replaced with the "geocode and search" API. This new API seems like it just looks through a list of stored points of interest within HERE’s database and returns the closest it can to what you have searched for, rather than trying to find the exact location entered.
How can I get more accurate results using the below request? Bare in mind that I will only have access to the postcode.
https://geocode.search.hereapi.com/v1/geocode?q={postCode}&apiKey={key}
At the moment I receive a response similar to the below using postcode PE1 1QL. It should be pointing to a car park, however if you enter the lat and lon returned from the API into a map E.g Google Maps, it gives you a more general location, rather than an accurate one.
{
"title": "PE1 1, Peterborough, England",
"id": "here:cm:namedplace:22221149",
"resultType": "locality",
"localityType": "postalCode",
"address": {
"label": "PE1 1, Peterborough, England",
"countryCode": "GBR",
"countryName": "England",
"county": "Cambridgeshire",
"city": "Peterborough",
"postalCode": "PE1 1"
},
"position": {
"lat": 52.57362,
"lng": -0.24219
},
"mapView": {
"west": -0.23515,
"south": 52.56739,
"east": -0.25194,
"north": 52.57984
},
"scoring": {
"queryScore": 0.67,
"fieldScore": {
"postalCode": 0.95
}
}
},
I would expect the Lat and Lng to be much closer to the postcode entered than the above example.
Regarding on this release notes https://developer.here.com/documentation/geocoding-search-api/release_notes/topics/known-issues.html
you can read "High precision postal codes are not yet supported":
Known Issues
The following table lists issues known to be present in the current release.
Search for intersections is not yet supported
Search by telephone numbers is not yet supported
Political views are not yet supported. All views are “International”
Places detail views are not yet supported
High precision postal codes are not yet supported
The Geocoder API 6.2 will be supported at least until end of 2020 (maybe more) and "Maintenance" in documentation means: no new features.

Here API: Can accept-language header be used to get filter addresses (French versus English)

We are using the places/search endpoint to look up addresses.
Being based in Ontario, a lot of addresses have French and English version.
For example, looking for 360 Lisgar Ottawa, on will return 2 addresses in French and 2 in English (https://places.demo.api.here.com/places/v1/discover/search?at=45%2C-75&q=360+Lisgar%2C+Ottawa%2C+on&addressFilter=countryCode%3DCAN&Accept-Language=en%3Bq%3D1%2Cfr%3Bq%3D0.1&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg).
We have been trying all kinds of combination of the "Accept-Language" header parameters, with different values and weight, and it always returns the 4 values. Is there any other way to only get the addresses in French or English?
We could filter in our code after, if there was any language field on the address returned, but we couldn't find any reference about it in the documentation. Is there any ways to do it?
Thanks,
Rene
The Accept-Language header is used in the here-api to indicate preference for language. However, if we have no translation/transliteration for a result in that language, we use a fallback mechanism where we try to return results in a language that would be intelligible to the user. In your case, I suspect that there are only French entries for some of the addresses and only English entries for others, which is why you get the same results no matter what you set the "Accept-Language" header to. There's no way to filter results so that if we don't have a translation in your preferred language then we don't return the result at all.
This might be worth trying as I can specify the language using the HERE Geocoder REST API by adding a parameter (the same format as the Google API) at the end:
&language=en
or
&language=ar
I work in Dubai so my other desired language is Arabic. See examples below.
Example REST API Call for English
https://geocoder.cit.api.here.com/6.2/geocode.json?app_id={your app id}&app_code={your app code}&searchText=1 Prince Fawaz St, Al Khobar&language=en
Example extract from the JSON return
"Address": {
"Label": "1 Prince Ahmad Street, Madinat Al Ummal, 34441 Al Khobar, Saudi Arabia",
"Country": "SAU",
"County": "Eastern Province",
"City": "Al Khobar",
"District": "Madinat Al Ummal",
"Street": "Prince Ahmad Street",
"HouseNumber": "1",
"PostalCode": "34441",
"AdditionalData": [
{
Example REST API Call for Arabic
https://geocoder.cit.api.here.com/6.2/geocode.json?app_id={your app id}&app_code={your app code}&searchText=1 Prince Fawaz St, Al Khobar&language=ar
Example extract from JSON return
"Address": {
"Label": "\u202e\u202a1\u202c شارع الأمير أحمد, مدينة العمال, \u202a34441\u202c الخبر, السعودية\u202c",
"Country": "SAU",
"County": "المنطقة الشرقية",
"City": "الخبر",
"District": "مدينة العمال",
"Street": "شارع الأمير أحمد",
"HouseNumber": "1",
"PostalCode": "34441",
"AdditionalData": [
{

How to get visitor location ( country, state and city ) using ASP.NET

I want to implement this in ASP.NET. I don't have any idea about how to do so, unfortunately.
Here how it is done in asp.net
Request.ServerVariables("REMOTE_ADDR")
Get a copy of IP adress database by location here
http://www.maxmind.com/
Why not use Google Analytics? You will get more than what you need. Alternatively you can get the client's ip and use service like ip2location to get the location.
Check this similar question as well. finding clients location in asp.net page.
by using
string userHost = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (String.IsNullOrEmpty(userHost) ||
String.Compare(userHost, "unknown", true) == 0)
{
userHost = Request.UserHostAddress;
}
you will get users ip address . Based on this ip address you can find out visitor location details by calling some webservice .
There are a few free web services out there which provide IP-to-location services. For instance:
http://freegeoip.net/
http://www.hostip.info/
http://ipinfodb.com/ip_location_api.php
IPAddressExtensions is a free codeplex class library if all you just want is the Country the IP is located from.
First, get the IP address of the visitor using Request.ServerVariables("REMOTE_ADDR").
Bear in mind that the visitor could be using a proxy server in which case the IP address may not be their actual IP address. For the proxy case, you can check if Request.ServerVariables("HTTP_X_FORWARDED_FOR") contains a value. This will be the actual IP address if the proxy server is not an anonymous proxy server.
Then you have 2 options, using a web service or querying data from your own database. Either way, you will need data which can match an IP address of the visitor to their country, state and city.
Using the geolocation API at ipStack (https://ipstack.com), I've used the following:
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
'url': 'https://www.freegeoip.net/json/#(HttpContext.Current.Request.UserHostAddress)',
'type': 'GET',
'success': function(data) {
// for example
if (data.country_code === "GB") {
... further logic here
}
}
});
});
</script>
It returns a lot of useful information, e.g.:
{
"ip": "134.201.250.155",
"hostname": "134.201.250.155",
"type": "ipv4",
"continent_code": "NA",
"continent_name": "North America",
"country_code": "US",
"country_name": "United States",
"region_code": "CA",
"region_name": "California",
"city": "Los Angeles",
"zip": "90013",
"latitude": 34.0453,
"longitude": -118.2413,
"location": {
"geoname_id": 5368361,
"capital": "Washington D.C.",
"languages": [
{
"code": "en",
"name": "English",
"native": "English"
}
],
"country_flag": "https://assets.ipstack.com/images/assets/flags_svg/us.svg",
"country_flag_emoji": "🇺🇸",
"country_flag_emoji_unicode": "U+1F1FA U+1F1F8",
"calling_code": "1",
"is_eu": false
},
"time_zone": {
"id": "America/Los_Angeles",
"current_time": "2018-03-29T07:35:08-07:00",
"gmt_offset": -25200,
"code": "PDT",
"is_daylight_saving": true
},
"currency": {
"code": "USD",
"name": "US Dollar",
"plural": "US dollars",
"symbol": "$",
"symbol_native": "$"
},
"connection": {
"asn": 25876,
"isp": "Los Angeles Department of Water & Power"
},
"security": {
"is_proxy": false,
"proxy_type": null,
"is_crawler": false,
"crawler_name": null,
"crawler_type": null,
"is_tor": false,
"threat_level": "low",
"threat_types": null
}
}
Get the client IP and find the location of IP using any IP to geo location Mapping service.

Resources