When sending city, postcode, country code in a structured query to the API, the results seem to be way off what is actually required.
Example #1 - City, Postcode, Country (removed API Key)
https://geocode.search.hereapi.com/v1/geocode?apiKey=XXXXX&qq=city=OXFORD;postalCode=OX2+0ES;country=GBR
This API call returns a result for postalCode OX1 3 which is not what I am looking for.
{
"title": "Oxford, England",
"id": "here:cm:namedplace:20338152",
"resultType": "locality",
"localityType": "city",
"address": {
"label": "Oxford, England",
"countryCode": "GBR",
"countryName": "England",
"countyCode": "OXF",
"county": "Oxfordshire",
"city": "Oxford",
"postalCode": "OX1 3"
},
"position": {
"lat": 51.75629,
"lng": -1.25951
},
Example #2 - Postcode, Country (removed API Key)
https://geocode.search.hereapi.com/v1/geocode?apiKey=XXXXX&qq=postalCode=OX2+0ES;country=GBR
This call returns the postcode OX2 0, which is closer to what I searched for, but still not accurate enough?
{
"title": "OX2 0, Oxford, England",
"id": "here:cm:namedplace:22218302",
"resultType": "locality",
"localityType": "postalCode",
"address": {
"label": "OX2 0, Oxford, England",
"countryCode": "GBR",
"countryName": "England",
"countyCode": "OXF",
"county": "Oxfordshire",
"city": "Oxford",
"postalCode": "OX2 0"
},
"position": {
"lat": 51.76224,
"lng": -1.27976
},
In some cases I have found while testing, is that the difference between the co-ordindates for the returned partial postcode and the full postcode is >= 8 miles out.
The question is, why when you attempt to be more accurate (including city) the response is inaccurate?
Also, if you are sending a full UK postcode to the Geocoder, why does it only resolve to part of the postcode? Surely if you send a full postcode, it should match?
Or, perhaps I need to use a different API. I did see another question with a similar issue that mentions Places API. Should this be used instead?
Related
The only difference between the two addresses is the number(housenumber).
Request_1:
https://geocoder.api.here.com/6.2/geocode.json?app_id={app_id}&app_code={app_code}&countryfocus=BRA&country=BRA&street=AVENIDA VEREADOR EDENITES DA SILVA VIANA&housenumber=244&city=São Francisco de Itabapoana&district=CENTRO&postalcode=28230000&state=RJ
Response_1: -21.47765, -41.10775
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Request_2:
https://geocoder.api.here.com/6.2/geocode.json?app_id={app_id}&app_code={app_code}&countryfocus=BRA&country=BRA&street=AVENIDA VEREADOR EDENITES DA SILVA VIANA&housenumber=160&city=São Francisco de Itabapoana&district=CENTRO&postalcode=28230000&state=RJ
Response_2: -21.47765, -41.10775
help, please
Reason behind same location position in response is because the matchLevel in your request is street so it doesn't matter if you will change the house number in the request, the position will point to the street address every time until it will find a housenumber/name.
"Result": [
{
"Relevance": 0.9,
"MatchLevel": "street",----> street is matched in response
"MatchQuality": {
"Country": 1.0,
"City": 1.0,
"Street": [
0.9
]
},
In the match quality there is no where it says hosuenumber like below response from the example-
"Result": [
{
"Relevance": 1,
"MatchLevel": "houseNumber",
"MatchQuality": {
"Country": 1,
"City": 1,
"Street": [
0.85
],
"HouseNumber": 1
},
To resolve this please enter the valid housenumber which matches this search.
https://developer.here.com/documentation/examples/rest/geocoder/latitude-longitude-by-partial-address
Want to display transit route near by location of my city, I can get it from next departure but if I want to get all Stops served by that specific route in sequence order?
Following is single object of station returned stations/by_geocoord.json
{
"id": "400702222",
"name": "Cosburn Ave at Woodbine Ave",
"distance": 24,
"duration": "PT0H0M24S",
"x": -79.317285,
"y": 43.696509,
"has_board": 1,
"country": "Canada",
"ccode": "CAN",
"state": "ON",
"postal": "M4C 4G4",
"district": "Woodbine-Lumsden",
"street": "Woodbine Ave",
"number": "1349",
"city": "Toronto",
"Transports": {
"Transport": [
{
"name": "87",
"mode": 5,
"dir": "West - 87A Cosburn towards Broadview Station via East York Acres",
"At": {
"textColor": "#FFFFFF",
"color": "#804000"
}
},
{
"name": "87",
"mode": 5,
"dir": "West - 87C Cosburn towards Broadview Station",
"At": {
"textColor": "#FFFFFF",
"color": "#804000"
}
}
]
}
}
How to get list of stops which are included in dir: West - 87A Cosburn towards Broadview Station via East York Acres
You can try this to get all the transit stations/stops within a given radius by using resource as stations/by_geocoord
Here is the Source for the documentation.
https://developer.here.com/documentation/transit/dev_guide/topics/resource-search-geocoord.html
I need to validate whether or not an address is a PO Box using the Geocoder API, and was thinking that the PostalCodeType result would provide me with the info, but it seems that supplying PO Box addresses returns different results.
For example, the following query is for a real-world PO Box:
?app_id={appId}&app_code={appCode}&country=USA&state=WA&searchtext=PO%20Box%20871570%20Vancouver%20WA%2098687&locationattributes=ar,mr,mv,dt,sd,ad,ai,li,in,tz,nb,rn&additionaldata=PreserveUnitDesignators,true
My expected output would be something along the lines of this:
...
"Address": {
"Label": "PO Box 871570, Vancouver, WA, United States",
"Country": "USA",
"State": "WA",
"County": "Clark",
"City": "Vancouver",
"PostalCode": "98687",
"AdditionalData": [
{
"value": "United States",
"key": "CountryName"
},
{
"value": "Washington",
"key": "StateName"
},
{
"value": "Clark",
"key": "CountyName"
},
{
"value": "P",
"key": "PostalCodeType"
}
]
}
...
However, I am getting this result, for a different postal code, without the PO Box info, and the PostalCodeType of N instead of P
...
"Address": {
"Label": "Vancouver, WA, United States",
"Country": "USA",
"State": "WA",
"County": "Clark",
"City": "Vancouver",
"PostalCode": "98660",
"AdditionalData": [
{
"value": "United States",
"key": "CountryName"
},
{
"value": "Washington",
"key": "StateName"
},
{
"value": "Clark",
"key": "CountyName"
},
{
"value": "N",
"key": "PostalCodeType"
}
]
}
...
Is there a better way to search PO Boxes?
Geocoder "PostalCodeType" parameter
for the USA, the Geocoder result shows supplementary information that describes the type of the 5-Digit ZIP, as according to the USPS. The values are as follows:
"N" = Non-Unique
"M" = Military
"P" = PO Box
"U" = Unique Zip
If you looking only for "P" value, then you can filter the JSON response at your end. Filtering additionalData, based upon postalCodeType is not feasible.
https://geocoder.api.here.com/6.2/geocode.json?app_id=xxxx&app_code=xxx&country=USA&state=WA&searchtext=PO%20Box%20871570%20Vancouver%20WA%2098687&locationattributes=ar,mr,mv,dt,sd,ad,ai,li,in,tz,nb,rn&additionaldata=PreserveUnitDesignators,true&addressattributes=pst
I need to be able to give a City/State or Postal Code and an Integer for the radius and return all cities/postal codes within the given radius using HERE but the Documentation seems to be unclear.
https://geocoder.api.here.com/6.2/reversegeocode.json?app_id=xxx&app_code=xxxx
The return is:
<ns2:Error xmlns:ns2="http://www.navteq.com/lbsp/Errors/1" type="PermissionError" subtype="InvalidCredentials">
<Details>invalid credentials for xxxxxxx</Details>
</ns2:Error>
But when I use
https://geocoder.api.here.com/6.2/geocode.json?app_id=xxx&app_code=xxxx
I get data back.
It is worth mentioning I am on the Freemium Package for the REST API
So first why can't I get data back from the Reverse Geo Code API?
And what is the appropriate string to accomplish the above?
Update:
Leaving the rest here in case someone else runs into this. To use Reverse Geo Code the API Route is actually
https://reverse.geocoder.api.here.com/6.2/reversegeocode.json
Though I still need some help on how to get the Radius Data
Update 2:
https://reverse.geocoder.api.here.com/6.2/reversegeocode.json?app_id=x&app_code=x&level=city&mode=retrieveAreas&prox=52.5309,13.3847,80467.2
Returns:
{
"Response": {
"MetaInfo": {
"Timestamp": "2019-04-27T17:47:41.043+0000"
},
"View": [
{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [
{
"Relevance": 1,
"Distance": 0,
"Direction": 0,
"MatchLevel": "district",
"MatchQuality": {
"Country": 1,
"State": 1,
"County": 1,
"City": 1,
"District": 1,
"PostalCode": 1
},
"Location": {
"LocationId": "NT_0ES-GaH3lZzJCuLQBrdw7C",
"LocationType": "point",
"DisplayPosition": {
"Latitude": 52.5309,
"Longitude": 13.3847
},
"MapView": {
"TopLeft": {
"Latitude": 52.54063,
"Longitude": 13.36566
},
"BottomRight": {
"Latitude": 52.50407,
"Longitude": 13.42964
}
},
"Address": {
"Label": "Mitte, Berlin, Deutschland",
"Country": "DEU",
"State": "Berlin",
"County": "Berlin",
"City": "Berlin",
"District": "Mitte",
"PostalCode": "10178",
"AdditionalData": [
{
"value": "Deutschland",
"key": "CountryName"
},
{
"value": "Berlin",
"key": "StateName"
},
{
"value": "Berlin",
"key": "CountyName"
}
]
},
"MapReference": {
"ReferenceId": "53500282",
"SideOfStreet": "neither",
"CountryId": "20147700",
"StateId": "20187401",
"CountyId": "20187402",
"CityId": "20187403",
"DistrictId": "20187417"
}
}
}
]
}
]
}
}
The documentation says to put in coordinates and a radius, that's 50 miles, so not sure why I am only receiving 1 city, Berlin, in the response.
Update 3:
https://reverse.geocoder.api.here.com/6.2/multi-reversegeocode.json?app_id=x&app_code=x&level=city&mode=retrieveAreas&prox=60.5544,-151.2583,80000
Tried with multi-reversegeocode
Return is: {}
Get cities in a proximity radius
Use the Reverse Geocode endpoint with the following parameters
https://reverse.geocoder.api.here.com/6.2/reversegeocode.json?
prox=52.5309,13.3847,80500 /* Note: 80.5 km around Berlin */
&app_id=YOUR_APP_ID
&app_code=YOUR_APP_CODE
&mode=retrieveAreas
&level=city
&gen=9
In short, your example in "Update 2" is correct, besides that it is missing the gen query parameter. Indeed, as per the API Reference, the query parameter level is valid only in combination with gen=2 or higher.
I have this file with JSON formatted data, but need this into a dataframe. Ultimately I would like to plot the geolocations onto a map, but can't seem to get this data into a df first.
json_to_df <- function(file){
file <- lapply(file, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
df <- do.call("rbind", file)
return(df)
}
But I get only this error:
Error in fromJSON(file) :
STRING_ELT() can only be applied to a 'character vector', not a 'list'
The file structure looks like this (this is only part of the data):
{
"results": [
{
"utc_offset": 7200000,
"venue": {
"country": "nl",
"localized_country_name": "Netherlands",
"city": "Bergen",
"address_1": "16 Notweg",
"name": "FitClub Bergen",
"lon": 4.699218,
"id": 24632049,
"lat": 52.673046,
"repinned": false
},
"headcount": 0,
"distance": 22.46796989440918,
"visibility": "public",
"waitlist_count": 0,
"created": 1467149834000,
"rating": {
"count": 0,
"average": 0
},
"maybe_rsvp_count": 0,
"description": "<p>Start your week off right with a Monday Morning Bootcamp!!! The fresh air and peaceful dunes provide the perfect setting for a total body workout. Whether you are a beginner with brand spankin' new health goals and in need of some direction, or training for a race or competition, we're the trainers for you!!! See you at 8:50 for sign-in!</p>",
"event_url": "https://www.meetup.com/FitClubBergen/events/234936736/",
"yes_rsvp_count": 3,
"duration": 3600000,
"name": "Free Bootcamp in the Bergen Dunes",
"id": "glzqvlyvnbgc",
"time": 1477292400000,
"updated": 1477297999000,
"group": {
"join_mode": "open",
"created": 1441658286000,
"name": "FitClub Bergen Free Bootcamp in the Dunes",
"group_lon": 4.710000038146973,
"id": 18908751,
"urlname": "FitClubBergen",
"group_lat": 52.66999816894531,
"who": "FitClubbers"
},
"status": "past"
},
{
"utc_offset": 7200000,
"venue": {
"country": "nl",
"localized_country_name": "Netherlands",
"city": "Bergen",
"address_1": "16 Notweg",
"name": "FitClub Bergen",
"lon": 4.699218,
"id": 24632049,
"lat": 52.673046,
"repinned": false
},
"headcount": 0,
"distance": 22.46796989440918,
"visibility": "public",
"waitlist_count": 0,
"created": 1467149834000,
"rating": {
"count": 0,
"average": 0
},
"maybe_rsvp_count": 0,
"description": "<p>Start your week off right with a Monday Morning Bootcamp!!! The fresh air and peaceful dunes provide the perfect setting for a total body workout. Whether you are a beginner with brand spankin' new health goals and in need of some direction, or training for a race or competition, we're the trainers for you!!! See you at 8:50 for sign-in!</p> <p>ALWAYS FREE</p> <p>FOR ALL LEVELS OF FITNESS</p> <p>BRING: water bottle and energy</p>",
"event_url": "https://www.meetup.com/FitClubBergen/events/234936737/",
"yes_rsvp_count": 3,
"name": "Monday Morning Bootcamp in the Bergen Dunes",
"id": "flzqvlyvnbgc",
"time": 1477292400000,
"updated": 1477303926000,
"group": {
"join_mode": "open",
"created": 1441658286000,
"name": "FitClub Bergen Free Bootcamp in the Dunes",
"group_lon": 4.710000038146973,
"id": 18908751,
"urlname": "FitClubBergen",
"group_lat": 52.66999816894531,
"who": "FitClubbers"
},
"status": "past"
},
{
"utc_offset": 7200000,
"venue": {
"country": "nl",
"localized_country_name": "Netherlands",
"city": "Amsterdam",
"phone": "020 4275777",
"address_1": "Dijksgracht 2",
"address_2": "1019 BS ",
"name": "Klimmuur Central",
"lon": 4.91284,
"id": 1143381,
"lat": 52.376626,
"repinned": false
},
"headcount": 0,
"distance": 1.0689502954483032,
"visibility": "public",
"waitlist_count": 0,
"created": 1477215767000,
"rating": {
"count": 0,
"average": 0
},
"maybe_rsvp_count": 0,
"description": "<p>Climbing Right After Work: RAW.<br/>Quiet hall, pretty much every rope available; no rope chasing necessary. And.. still some time left to do other things later that evening. Take you gear and an extra sandwich to work and join me afterwards pulling some plastic.<br/>Some notes:<br/>- This events starts #17:00. If you can't make it that early, please comment the time you can.<br/>- Please fill in your belaying skills in your profile. If you've never climbed before or don't have belaying skills: follow an introduction course a the gym first! Safety above all!</p>",
"event_url": "https://www.meetup.com/The-Amsterdam-indoor-rockclimbing/events/235054729/",
"yes_rsvp_count": 3,
"name": "Monday's RAW Climb",
"id": "235054729",
"time": 1477321200000,
"updated": 1477334279000,
"group": {
"join_mode": "approval",
"created": 1358348565000,
"name": "The Amsterdam indoor rockclimbing",
"group_lon": 4.889999866485596,
"id": 6689952,
"urlname": "The-Amsterdam-indoor-rockclimbing",
"group_lat": 52.369998931884766,
"who": "Climbers"
},
"status": "past"
},
{
"utc_offset": 7200000,
"venue": {
"country": "nl",
"localized_country_name": "Netherlands",
"city": "Amstelveen",
"address_1": "Langs de Akker 3",
"name": "Emergohal",
"lon": 4.87967,
"id": 23816542,
"lat": 52.290199,
"repinned": false
},
"rsvp_limit": 12,
"headcount": 0,
"distance": 5.541957378387451,
"visibility": "public",
"waitlist_count": 0,
"created": 1474452073000,
"fee": {
"amount": 5.5,
"accepts": "cash",
"description": "per person",
"currency": "EUR",
"label": "price",
"required": "0"
},
"rating": {
"count": 0,
"average": 0
},
"maybe_rsvp_count": 0,
"description": "<p>We will play the Whole Season indoor soccer on Mondays from 18:00 - 19:00 starting 5 September until May 2017 in the Emergohal Amstelveen.</p> <p>Preferred payment is with Paypal EUR 5.50 (in advance)<br/>If this is not possible you may pay cash but then I will ask EUR 6,-<br/>(Please have the exact cash with you)</p> <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p> <p>A couple of Unisys (ex)colleagues and football lovers are playing every Monday in the Emergohal Amstelveen at 6PM on a reasonable good level. We are looking for a compact group of players who are willing/able to play (almost) every Monday playing 5v5 (or 6v6).<br/>We are playing with the FIFA Futsal rules in mind:<br/>http://www.fifa.com/mm/document/footballdevelopment/refereeing/51/44/50/lawsofthegamefutsal2014_15_eneu_neutral.pdf</p> <p>The Emergohal has dressing rooms and a nice bar for after the game.</p> <p>Hope to see you on Mondays</p> <p>Cheers Jeroen</p> <p>For questions you may call me on[masked], send a text message (SMS) or leave a message on this meetup group.</p>",
"event_url": "https://www.meetup.com/Futsal_Emergohal_Monday_18-00/events/234290812/",
"yes_rsvp_count": 11,
"duration": 4500000,
"name": "Futsal",
"id": "234290812",
"time": 1477323900000,
"updated": 1477330559000,
"group": {
"join_mode": "approval",
"created": 1474445066000,
"name": "Futsal_Emergohal_Monday_18.00",
"group_lon": 4.860000133514404,
"id": 20450096,
"urlname": "Futsal_Emergohal_Monday_18-00",
"group_lat": 52.31999969482422,
"who": "Players"
},
"status": "past"
}],
"meta": {
"next": "https://api.meetup.com/2/open_events?and_text=False&offset=1&city=Amsterdam&sign=True&format=json&lon=4.88999986649&limited_events=False&photo-host=public&page=20&time=-24m%2C&radius=25.0&lat=52.3699989319&status=past&desc=False",
"method": "OpenEvents",
"total_count": 643,
"link": "https://api.meetup.com/2/open_events",
"count": 20,
"description": "Searches for recent and upcoming public events hosted by Meetup groups. Its search window is the past one month through the next three months, and is subject to change. Open Events is optimized to search for current events by location, category, topic, or text, and only lists Meetups that have **3 or more RSVPs**. The number or results returned with each request is not guaranteed to be the same as the page size due to secondary filtering. If you're looking for a particular event or events within a particular group, use the standard [Events](/meetup_api/docs/2/events/) method.",
"lon": ,
"title": "Meetup Open Events v2",
"url": "",
"signed_url": "{signed_url}",
"id": "",
"updated": 1479988687055,
"lat":
}
}
So I was wondering how I would put this in a dataframe or csv even to be able to extract geolocations later?
There is no need to write a parser yourself, there are a number of packages that can read JSON formatted data. The one I use, and #hrbrmstr linked, is jsonlite. This package provides a fromJSON function which can parse JSON into a data.frame:
fromJSON('file.json', flatten = TRUE)
note that the flatten argument here ensures the json is flattended into a nice data.frame.