Multi Reverse Geocoding API 500 Error - here-api

https://reverse.geocoder.cit.api.here.com/6.2/multi-reversegeocode.json?app_id=MYID&app_code=MYCODE&gen=8&mode=retrieveAddress
Get Parameters
app_id=MYID
app_code=MYCODE
gen=8
mode=retrieveAddress
Headers
Content-Type=*
Cache-Control=no-cache
Post Body
prox=44.97750,-93.26899,50
prox=44.93909,-93.28083,50
Returns a 500 error with the response body being
{"type":"SystemError"}
This error doesn't provide me with any useful information as to what is wrong. Is there something wrong with my request or is this on Here's side?

here is a link to the API description that should help you with a successful post request: https://developer.here.com/rest-apis/documentation/geocoder/topics/request-first-multi-reverse-geocode.html
Looks like your post body doesn't include an "id". But you need that as otherwise you will not be able input to results, which is important when you don't limit maxresults to "1" and you are very likely get multiple results per input coordinate back.
I also recommend to set gen=9 and increase the radius from 50 to at least 250 meters. Because when your input point is further away than 50 meters from a road you can easily get back an area level fallback. Results are ranked by distance to input coordinate anyway, so a larger radius doesn't hurt at all.
id=0001&prox=44.97750,-93.26899,250
id=002&prox=44.93909,-93.28083,250

Related

Avoid Areas not working in Here Fleet Telematics

Im using the "avoidareas" parameter to remove some points from the initial trip. This method worked a couple of months ago, but now it returns the same route as the initial trip, ignoring the "avoidareas" parameter.
Here is the exemple im working with:
"https://fleet.ls.hereapi.com/2/calculateroute.json?apiKey={YOUR API KEY}&mode=fastest;truck;traffic:enabled;&currency=EUR&restTimes=EU&traverseGates=true&tollVehicleType=3&trailerType=2&trailersCount=1&length=13.6&width=2.4m&height=3m&limitedWeight=24000kg&legAttributes=li,-mn,sh&linkAttributes=wn,le,sh,-fc&mapMatchRadius=5000&ignoreWaypointVehicleRestriction=5000;0;all&departure=2022-09-08T16:00:00&waypoint0=40.613223,-3.2451044&waypoint1=39.919898,-8.634333&avoidareas41.6419,-5.16831;41.541900000000005,-5.06831"
Am i doing something wrong? Has something been updated?
The 'avoidAreas' feature works, but the request needs to be verified for the following:
the parameter name is in camelCase, so it should be 'avoidAreas', you are missing "=" sign right after avoidareas in your request url,
avoid area rectangle should be specified by latMax,lonMin;latMin,lonMax
A sample request looks like https://fleet.api.here.com/2/calculateroute.json?waypoint0=50.112698,8.675777&waypoint1=48.544180,9.662530&mode=fastest;truck;traffic:enabled&departure=2022-08-09T13:12:35&alternatives=0&weightPerAxle=3.25t&limitedWeight=7.5t&height=3.4m&width=2.5m&length=7.2m&trailersCount=1&avoidAreas=48.988757459020015,8.436328214242295;48.94714399157084,8.493687099461848
Thanks
/MS

Routing with avoid area and geofence / polygon

I want to avoid specific streets when using the routing API. I have data points to create a geofence or polygon to represent those specific streets.
The router API accepts only up to 20 bounding boxes. I tried to send 20 avoid area bounding boxes to represent the road, but the result is not reliable (e.g. on diagonal roads).
Is there a way to send a geofence/polygon instead of bounding boxes?
Or any other way to avoid certain streets?
Thank you very much
Please try to use avoid[segments] instead of avoid[areas] for avoiding specific roads. In the case of having too many roads to avoid, you can also put the avoid[segments] parameters into request body and send a POST request to the same endpoint.
In order to get the segmentId of the roads you would like to avoid, you can do a normal routing call with parameter spans=segmentId added and then look at the topologySegmentId attributes in spans section of the response.
https://developer.here.com/documentation/routing-api/api-reference-swagger.html
HERE Routing API now supports polygons for avoid area, https://www.here.com/learn/blog/routing-supports-polygons-for-avoid-areas
You have to make below calls for your usecase.
1>Rest call to get segmentId For the route.
https://router.hereapi.com/v8/routes? apikey={your_app_id}& origin=32.834496,74.81515& destination=32.811632,75.816037& return=polyline,summary,actions,instructions& spans=segmentId& transportMode=car&
2>Rest Call to get the get Route with avoid[segments]
https://router.hereapi.com/v8/routes? apikey={your_app_id}& origin=32.834496,74.81515& destination=32.811632,74.816037& return=polyline,summary,actions,instructions& spans=segmentId& transportMode=car& avoid[segments]=here:cm:segment:808368834,here:cm:segment:808095972

Google Maps API queryautocomplete location parameter doesn't work

I'm trying to use "location" parameter for queryautocomplete command in Google Maps API. But whatever coordinates I give, it returns the same results. I just need to get search suggestions of places nearby the location coordinates. Here is query example:
https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=%D0%BF%D1%80%D0%BE%D1%81%D0%BF%D0%B5%D0%BA%D1%82&key=*******&location=53.2415041,50.22124629999996&language=ru
**** is key ID
Does anybody know how to solve it?
дружба
define a radius too.
Currently you get a place in moskow as first result, although the location is in samara(but the returned places are more prominent , e.g. mir prospect in moscow)
Sample request with radius a radius of 50km:
https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=%D0%BF%D1%80%D0%BE%D1%81%D0%BF%D0%B5%D0%BA%D1%82&location=53.2415041,50.22124629999996&radius=50000&key=yourkey
First result: lenin prospect, samara

Errors When Calculating Distance Between Two Addresses

I have the following script which is being used in a spreadsheet to calculate the driving distance between two cities or a city and a zip code of another city. It is being run for approximately 25 locations simultaneously. To better explain, I have cell B3 in which I enter a new city every time. The script is then used in cells adjacent to my 25 plant locations to calculate the distance from each of my plants to the variable city.
It uses google sheets built in mapping api and works on 80% of the calculations but returns "TypeError: Can Not Read Property "legs" from undefined. (line 16). The plants that it fails on vary with every new city so its not like it is for certain locations. It is almost like the api times out before it completes some of them. I split it into two separate scripts with a varied name and that worked for a day but then 20% fail again.
To make things slightly more odd, I have another script that sorts the plants based on closest distance to the variable address. When you sort the plants, even the ones with errors go to their correct location based on distance. So it is like the distance script is obtaining the correct disance but displaying the error anyways.
Clear as mud? Would love any input I could get on how to correct the issue or an alternate mapping api that could solve my problems.
function distancecalcone(origin,destination) {
var directions = Maps.newDirectionFinder()
//Set the Method of Transporation. The available "modes" are WALKING, DRIVING, BICYCLING, TRANSIT.
.setMode(Maps.DirectionFinder.Mode.DRIVING)
//Set the Orgin
.setOrigin(origin)
//Set the Destination
.setDestination(destination)
//Retrieve the Distance
.getDirections();
return directions.routes[0].legs[0].distance.value/1609.34;
}
Have you tried using a try-catch block around directions.routes[0].legs[0].distance.value ?
try{
return directions.routes[0].legs[0].distance.value/1609.34;
}
catch (e){
console.log("error",e)
}
or you could try something like this
alert(directions);
alert(directions.routes[0]);
alert(directions.routes[0].legs[0]);
alert(directions.routes[0].legs[0].distance);
alert(directions.routes[0].legs[0].distance.value);
and so on...to find out which one comes up as undefined the first. That might help you to debug the issue.
Enable Direction Api
1)Go to "google cloud platform"
2)go to "Api and services"
3)search for "direction api" and enable it
The directions service is subject to a quota and a rate limit. Check the return status before parsing the result.
For lots of distances (or at least more than 10), look at the DistanceMatrix.
I'm able to run the script from the Script editor, but not from spreadsheet. The error is "unable to read property legs" when the function is called from spreadsheet. But the property is in place when called from Script editor and contain correct values.
You probably need to use WEB API and have API KEY:
Google Apps Script - How to get driving distance from Maps for two points in spreadsheet

Dynamically set bounds on nearbySearch based on search critieria

We've implemented a search box and google maps on our page to allow customers to perform searches based on places queries, and so far it's working well. However, using TextSearch we almost always get 20 results (unless it's a specific point). What we prefer though, is to return a set of results that makes more sense to a user based on their search (i.e. if they're searching for churches within a zipcode, we shouldn't show churches outside the zip code).
I know we can bias our results based on location and radius, and even restrict results based on location / radius using NearbySearch.
However, our customers are national users who may be searching in any area in the world, so we're not sure, until the user searches, what location and radius to set as a restriction. I'd like to determine that dynamically based on their query.
For example, in Google Maps if you search for "Churches near 30319" you get a much more localized result set than "Churches near Georgia"
Churches near 30319:
https://maps.google.com/maps?q=churches+near+30319&hl=en&sll=33.772251,-84.296934&sspn=0.049158,0.082312&hq=churches&hnear=Atlanta,+Georgia+30319&t=m&z=14
Churches near Georgia:
https://maps.google.com/maps?q=churches+near+Georgia&hl=en&sll=33.870438,-84.332304&sspn=0.049102,0.082312&hq=churches&hnear=Georgia&t=m&z=8
I've tested doing a separate query using geocode to get the single-point location of the query. i.e.
getGeneralVicinity = ->
address = $('#address').val()
window.oneq.geocode.geocoder.geocode
address: address,
(results, status) ->
if status is google.maps.GeocoderStatus.OK
console.log(results[0].types)
It seems by possibly finding the type of the geocode result (i.e locality) we could determine a radius and use the geometry.location for the location bounds. Unfortunately, it's not consistent, and if a user only searches for "churches", this doesn't give us the desired results.
Any help would be greatly appreciated.
You almost had it. I will refer to the Geocoding API as its JSON feed rather than the Google implementation of it, so detail will come straight from the source. There are some very interesting parameters that come back when geocoding something. Try it:
Georgia: http://maps.googleapis.com/maps/api/geocode/json?address=georgia&sensor=true
30319:http://maps.googleapis.com/maps/api/geocode/json?address=30319&sensor=true
Both of the second-tier address components are Georgia. However, there are a few differing parameters, and the one you want is geometry. This indicates the shape of the area.
Take, for example, the 30319 request. You will get as bounds:
"bounds" : {
"northeast" : {
"lat" : 33.9203610,
"lng" : -84.30943599999999
},
"southwest" : {
"lat" : 33.83286890,
"lng" : -84.35826589999999
}
},
"location" : {
"lat" : 33.87309460,
"lng" : -84.33842899999999
},
This tells you three things:
The corners of the bounding box
The centre of the box (which will be the intersection of the vertex lines)
This allows you to compute the maximum distance from your centre, which you can then feed back into your google places API search as radius. Conversion from lat/long to distance is trivial: it's called the orthodromic path. Two formulas exist - one for small distances (Haversine's formula), the other for large distances (this). Someone wrote a calculator for these: http://williams.best.vwh.net/gccalc.htm . You'll quickly see that the bounding box for 30319 spans 10km, whilst the georgia one spans almost 700 (which would require multiple Google Places requests to match).
Let me know if this wasn't clear and I'll elaborate further.

Resources