I have the GPS co ordinate of the user on a map (Indicated by red dot in the picture)
I would like to calculate the GPS co ordinates of the blue dots on the map.
The dots are equidistant from the red dot on either side. If I can get the heading of the street compared to magnetic north I can calculate the dots or is there any other easy way?
(I tested it use map version 1, not map api V2.)
Before follow steps, you should know distance and angle before finding coordinates.
Steps:
Change geo point to pixel(x, y). (Use projection)
Get pixel size of distance(d). (Use metersToEquatorPixels)
Then you get a point (d, 0)
Rotate (d,0) ==> You will get a new point which spaced apart at d from (0, 0) ==> (a, b)
(x+a, b+y) is a point that you want.
Get geo coordinate of (x+a, y+b) use this.
Rotation formular is
(x'*cos(θ) - y'*sin(θ), x'*sin(θ) + y'*cos(θ))
so, you can change this simple.
(d*cos(θ), d*sin(θ)) // This is a point of step 4. (a,b)
My code is.
// you should know distance and angle
Point px = new Point();
Point px2 = new Point();
mapView.getProjection().toPixels(mGeoPt, px);
float pixedDis = mapView.getProjection().metersToEquatorPixels(distance);
px2.x = (int)(pixedDis*Math.cos(angle)) + px.x;
px2.y = (int)(pixedDis*Math.sin(angle)) + px.y;
GeoPoint gp3 = mapView.getProjection().fromPixels(px2.x, px2.y);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With