Find the nearest index of polyline to the given location
up vote
0
down vote
favorite
How can I get the nearest point from my location in a polyline? I have used the below code to do my job
click here to view code
but it gives me output something like this:
List<LatLng> points = new ArrayList<>();
points.add(new LatLng(2, 2));
points.add(new LatLng(4, 2));
points.add(new LatLng(4, 4));
points.add(new LatLng(2, 4));
points.add(new LatLng(2, 2));
LatLng testPoint = new LatLng(3, 0);
LatLng nearestPoint = findNearestPoint(testPoint, points);
Log.e("NEAREST POINT: ", "" + nearestPoint); // lat/lng: (3.0,2.0)
But I want the index of the polyline (ArrayList containing a list of Polyline) which is closest to the given point, I have tried many methods but none of them worked out.
Please let me know if you got the solution.
android google-maps maps polyline
add a comment |
up vote
0
down vote
favorite
How can I get the nearest point from my location in a polyline? I have used the below code to do my job
click here to view code
but it gives me output something like this:
List<LatLng> points = new ArrayList<>();
points.add(new LatLng(2, 2));
points.add(new LatLng(4, 2));
points.add(new LatLng(4, 4));
points.add(new LatLng(2, 4));
points.add(new LatLng(2, 2));
LatLng testPoint = new LatLng(3, 0);
LatLng nearestPoint = findNearestPoint(testPoint, points);
Log.e("NEAREST POINT: ", "" + nearestPoint); // lat/lng: (3.0,2.0)
But I want the index of the polyline (ArrayList containing a list of Polyline) which is closest to the given point, I have tried many methods but none of them worked out.
Please let me know if you got the solution.
android google-maps maps polyline
That functionfindNearestPoint
is finding a point somewhere on the line segments specified in the list closest to the specified point - it is not necessarily finding the closest vertex (or the points in your list)..
– Andy
Nov 7 at 17:10
Take a look at stackoverflow.com/questions/36104809/…
– antonio
Nov 7 at 20:06
@antonio Hi, I used your code to get the closest polyline index of the given point but as Andy said it is finding a point somewhere in the line segment. So, How can I get the index of polyline list ?
– Adarsh
Nov 9 at 3:57
@Adarsh Don't use that function - just loop on yourpoints
, useSphericalUtil.computeDistanceBetween
and find the minimum distance and that is your point/index. For long lists you'll have to consider optimization.
– Andy
Nov 10 at 15:20
@Andy ok thanks for your answer anyhow I have used this code github.com/googlemaps/android-maps-utils/blob/master/library/… to get the index and it's working perfectly
– Adarsh
Nov 11 at 7:13
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How can I get the nearest point from my location in a polyline? I have used the below code to do my job
click here to view code
but it gives me output something like this:
List<LatLng> points = new ArrayList<>();
points.add(new LatLng(2, 2));
points.add(new LatLng(4, 2));
points.add(new LatLng(4, 4));
points.add(new LatLng(2, 4));
points.add(new LatLng(2, 2));
LatLng testPoint = new LatLng(3, 0);
LatLng nearestPoint = findNearestPoint(testPoint, points);
Log.e("NEAREST POINT: ", "" + nearestPoint); // lat/lng: (3.0,2.0)
But I want the index of the polyline (ArrayList containing a list of Polyline) which is closest to the given point, I have tried many methods but none of them worked out.
Please let me know if you got the solution.
android google-maps maps polyline
How can I get the nearest point from my location in a polyline? I have used the below code to do my job
click here to view code
but it gives me output something like this:
List<LatLng> points = new ArrayList<>();
points.add(new LatLng(2, 2));
points.add(new LatLng(4, 2));
points.add(new LatLng(4, 4));
points.add(new LatLng(2, 4));
points.add(new LatLng(2, 2));
LatLng testPoint = new LatLng(3, 0);
LatLng nearestPoint = findNearestPoint(testPoint, points);
Log.e("NEAREST POINT: ", "" + nearestPoint); // lat/lng: (3.0,2.0)
But I want the index of the polyline (ArrayList containing a list of Polyline) which is closest to the given point, I have tried many methods but none of them worked out.
Please let me know if you got the solution.
android google-maps maps polyline
android google-maps maps polyline
edited Nov 9 at 10:16
MrUpsidown
14.5k74893
14.5k74893
asked Nov 7 at 12:19
Adarsh
22
22
That functionfindNearestPoint
is finding a point somewhere on the line segments specified in the list closest to the specified point - it is not necessarily finding the closest vertex (or the points in your list)..
– Andy
Nov 7 at 17:10
Take a look at stackoverflow.com/questions/36104809/…
– antonio
Nov 7 at 20:06
@antonio Hi, I used your code to get the closest polyline index of the given point but as Andy said it is finding a point somewhere in the line segment. So, How can I get the index of polyline list ?
– Adarsh
Nov 9 at 3:57
@Adarsh Don't use that function - just loop on yourpoints
, useSphericalUtil.computeDistanceBetween
and find the minimum distance and that is your point/index. For long lists you'll have to consider optimization.
– Andy
Nov 10 at 15:20
@Andy ok thanks for your answer anyhow I have used this code github.com/googlemaps/android-maps-utils/blob/master/library/… to get the index and it's working perfectly
– Adarsh
Nov 11 at 7:13
add a comment |
That functionfindNearestPoint
is finding a point somewhere on the line segments specified in the list closest to the specified point - it is not necessarily finding the closest vertex (or the points in your list)..
– Andy
Nov 7 at 17:10
Take a look at stackoverflow.com/questions/36104809/…
– antonio
Nov 7 at 20:06
@antonio Hi, I used your code to get the closest polyline index of the given point but as Andy said it is finding a point somewhere in the line segment. So, How can I get the index of polyline list ?
– Adarsh
Nov 9 at 3:57
@Adarsh Don't use that function - just loop on yourpoints
, useSphericalUtil.computeDistanceBetween
and find the minimum distance and that is your point/index. For long lists you'll have to consider optimization.
– Andy
Nov 10 at 15:20
@Andy ok thanks for your answer anyhow I have used this code github.com/googlemaps/android-maps-utils/blob/master/library/… to get the index and it's working perfectly
– Adarsh
Nov 11 at 7:13
That function
findNearestPoint
is finding a point somewhere on the line segments specified in the list closest to the specified point - it is not necessarily finding the closest vertex (or the points in your list)..– Andy
Nov 7 at 17:10
That function
findNearestPoint
is finding a point somewhere on the line segments specified in the list closest to the specified point - it is not necessarily finding the closest vertex (or the points in your list)..– Andy
Nov 7 at 17:10
Take a look at stackoverflow.com/questions/36104809/…
– antonio
Nov 7 at 20:06
Take a look at stackoverflow.com/questions/36104809/…
– antonio
Nov 7 at 20:06
@antonio Hi, I used your code to get the closest polyline index of the given point but as Andy said it is finding a point somewhere in the line segment. So, How can I get the index of polyline list ?
– Adarsh
Nov 9 at 3:57
@antonio Hi, I used your code to get the closest polyline index of the given point but as Andy said it is finding a point somewhere in the line segment. So, How can I get the index of polyline list ?
– Adarsh
Nov 9 at 3:57
@Adarsh Don't use that function - just loop on your
points
, use SphericalUtil.computeDistanceBetween
and find the minimum distance and that is your point/index. For long lists you'll have to consider optimization.– Andy
Nov 10 at 15:20
@Adarsh Don't use that function - just loop on your
points
, use SphericalUtil.computeDistanceBetween
and find the minimum distance and that is your point/index. For long lists you'll have to consider optimization.– Andy
Nov 10 at 15:20
@Andy ok thanks for your answer anyhow I have used this code github.com/googlemaps/android-maps-utils/blob/master/library/… to get the index and it's working perfectly
– Adarsh
Nov 11 at 7:13
@Andy ok thanks for your answer anyhow I have used this code github.com/googlemaps/android-maps-utils/blob/master/library/… to get the index and it's working perfectly
– Adarsh
Nov 11 at 7:13
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189359%2ffind-the-nearest-index-of-polyline-to-the-given-location%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
That function
findNearestPoint
is finding a point somewhere on the line segments specified in the list closest to the specified point - it is not necessarily finding the closest vertex (or the points in your list)..– Andy
Nov 7 at 17:10
Take a look at stackoverflow.com/questions/36104809/…
– antonio
Nov 7 at 20:06
@antonio Hi, I used your code to get the closest polyline index of the given point but as Andy said it is finding a point somewhere in the line segment. So, How can I get the index of polyline list ?
– Adarsh
Nov 9 at 3:57
@Adarsh Don't use that function - just loop on your
points
, useSphericalUtil.computeDistanceBetween
and find the minimum distance and that is your point/index. For long lists you'll have to consider optimization.– Andy
Nov 10 at 15:20
@Andy ok thanks for your answer anyhow I have used this code github.com/googlemaps/android-maps-utils/blob/master/library/… to get the index and it's working perfectly
– Adarsh
Nov 11 at 7:13