i want to calculate how many pixels there are between 2 points on my screen.
I’ve seen that i can draw a straight line between 2 points using Path class, but i don’t really want to draw that line, i only want to know how long is it in pixels..
i really need it for my MapView clusters implementation..
i can get each marker position on screen with no problem, but don’t know how to calculate pixel’s “distance” between them …
i know that there are cluster’s implementations available but i want to try and create one of my own
help will be appreciated 🙂
This is very straightforward using a bit of algebra 🙂
Take the co-ordinates of both points and calculate the difference between their x and y values e.g.
Where
p1andp2are the points you want get find the distance between, anddistanceis the result. It will be a double but you can round it to the nearestintif you wish