I'm making a delivery site and I need to calculate the distance between two points and set a minimum price and multiply every 100 meters. How can this be done?
If you want the driving distance (and you are displaying a Google Map), you can use the directions service or the directions matrix
Related
I need help defining/clarifying a problem I am trying to solve.
I have n points in one dimension. Each point has its own range that it can move between. They cannot move outside of that range. I need to "spread" the points out as much as possible. I want to maximize the distance between all adjacent points. What is a more formal way to say this?
Using a smaller example:
I can move the left and right points to the sides as much as possible. Then I can find the midpoint of this distance and move the middle point to that midpoint as much as possible.
I have maximized the average distance between all points but I have also minimized the variance of the distances as well.
These seem like the two core restraints I need to "spread out" the points as much as possible. I eventually need to develop an algorithm that can do this with an arbitrary number of points.
Am I correct that I need to maximize the average distance of all points while also minimizing the variance of these nearest neighbor distances?
I'm just playing around with Here and this is my escenario for an idea.
Get a routing between 2 points, I know this is doable
Set the start and finish marker, I know this is doable
Get the distance between the 2 points, I know this is doable
Now, if the distance from point 1 and 2 is 3000 meters I want to set a marker ( You are here ) based on a arbitrary distance value, let say I want to add a marker at the 1750 meters point, the market should appears in the half route way.
Is this posible with the actual API?
Thanks in advance!
Yes it is possible to do with HERE javascript API.
Once you get routing response and create H.geo.LineString out of it, you can calculate distance between each two geo points from that line string using H.geo.Point#distance method. This will help to determine between which two points (lat, lng) is your desired arbitrary distance.
After that you need to calculate angle between these two geo points and use it in method H.geo.Point#walk in order to get exact position of the geo point you need.
Here you can find jsfiddle example which places marker on the simple LineString based on desired arbitrary distance.
I need to create clusters from the distance between clients if the distance between the points is less than certain precise value group them together.
I thought about using Delaunay but I'm not having success
I am new to here-api and have a question wrt distance as shown in the response to a calculateroute request. Having a sequence of 100 waypoints recorded by GPS device along a road (~ 20m apart) the distance in the summary tag of the response is very different from what I calculate when summing up the distances between waypoints involved. Also bringing the waypoint sequence to a map shows that the summed up value is close to reality. whats going wrong here?
When sending a request like this
https://route.api.here.com/routing/7.2/calculateroute.json
?app_id=<my_app_id>
&app_code=<my_app_code>
&wayPoint0=geo!45.008503,7.555000
&wayPoint1=geo!45.006691,7.554025
&wayPoint2=geo!45.006470,7.554040
&wayPoint3=geo!45.006290,7.554018
&wayPoint4=geo!45.006096,7.553948
&wayPoint5=geo!45.005875,7.553872
&wayPoint6=geo!45.005615,7.553765
&wayPoint7=geo!45.004444,7.553305
&wayPoint8=geo!45.004116,7.553172
&wayPoint9=geo!45.003792,7.553035
&wayPoint10=geo!45.003460,7.552888
&routeattributes=routeId,waypoints,shape
&mode=shortest;car;traffic:disabled&returnelevation=true
I get a response consisting of 11 waypoints and 78 shapepoints. Calculating the distance via waypoints (using Haversine formula) yields a value of ~ 600 meters which looks reasonable and can be verified when exporting the result to kml and put on a map. However the distance tag under the summary section reports a distance of 3000 meters. Also the summed distance over shape points is much too high (2900m).
Most likely your GPS probes are not exactly on the road and calculateroute will compute a complex result.
When having a list of GPS tracks, you should use instead Route Map Extension (RME) that will figure out the correct/most probable route.
I am running a taxicab distance function on a list of coordinates and I would like to convert the outcome integer to a mile or km quantity. For example:
0.0117420 = |40.721319 - 40.712278| + |-73.844311 - -73.841610|
Where 0.0117420 is the output I would like to convert to mi/km. How could I go about this?
This appears to be a situation where you are trying to navigate from (40.721319, -73.844311) to (40.712278, -73.841610) where these are lat / lon pairs, and you want to navigate using a "Manhattan" routing rather than a direct great circle route.
It looks like you are considering these points as opposite corners of a "rectangle" where travel is only allowed along north, south, east and west headings to move from one point to another and where travel along the path always brings the traveler closer to the destination point.
An approximation of this is to find one of the corners of the bounding rectangle for all such paths. There are two of them, one at (40.721319, -73.841610) and the other at (40.712278, -73.844311). So, you can pick one of these and chose that as a waypoint for approximating the length each possible "Manhattan routes" between the two points. If we chose the first, you will need to calculate the distance from the starting point to the waypoint then to the destination point. Such as:
l(0) = (40.721319, -73.844311)
l(1) = (40.721319, -73.841610)
l(2) = (40.712278, -73.841610)
Using the Haversine equations we see the distance from l(0) to l(1) is approximately 0.2276km and the distance from l(1) to l(2) is approximately 1.005km making the entire route about 1.2326km.
This is approximately the length of any "Manhattan route" you pick where the distance is strictly decreasing along the path taken between the two points. There are also some errors due to the curvature of the Earth, but for points this close to each other and so distant from either of the poles, this should be good enough for most applications.