Question

I need to map my current location seen on map (say A) to a different screen on my app (say B which does not have a map background). I have my current location plotted on the map and I know the lat/long values.

  Location loc = mProjInstance.locationManager.getLastKnownLocation(Constants.provider2);

gave me the coordinates.

Now on the screen B, i have been using the center of the device screen

    int x = ((MapView)mParent).getWidth()/2;
    int y = ((MapView)mParent).getHeight()/2;

To plot two concentric circles around the center (x,y).

Now I need to plot the circles on B, not using the center of the device, but using the lat/long obtained using the getLastKnownLocation mentioned above.

So i provided x and y the values like this

 Location loc1 = PROJ.getInstance().locationManager.getLastKnownLocation(Constants.provider2);  
            x = (int) loc1.getLatitude();
            y = (int) loc1.getLongitude();

          canvas.drawCircle( x, y,innerRadius, mSelectionBrush);
          canvas.drawCircle( x, y,outerRadius, mSelectionBrush);

But when i try this, the circles on 'B' are at a different position as compared to A. B plots the center at the top left corner of the screen, while A plots it properly approximately at the center of the screen, my current geographic location.

My question is how do i convert the lat/long values to fit properly into the float parameters of canvas.drawCircle.

I debugged the values, The value for x and y I see in screen A are x=240,y=285 - Center of screen. (This is the correct location)

But when i do the conversion in the current(faulty)way, for screen B x=19,y=72 - Towards the top left corner of the screen (Incorrect)

No correct solution

OTHER TIPS

Here are the salient lines (lots omitted) of an overlay I used to show accuracy on a GoogleMap (v1) overlay. You should get the general idea and be able to adapt it to v2

public class AccuracyOverlay extends com.google.android.maps.Overlay {

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
            long when) {

        super.draw(canvas, mapView, shadow);
        float accuracyRad = 100.0f; // 100 metres as an example
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setAlpha(16);// +lots more set() methods applied
        Point p1 = new Point();
        CommonPosition cp = CommonPosition.getInstance();
        // Last position
        GeoPoint lastFixGp = new GeoPoint(cp.getLatitudeE6(),
                    cp.getLongitudeE6());

        mapView.getProjection().toPixels(lastFixGp, p1);
        canvas.drawCircle(p1.x, p1.y, accuracyRad, paint);
        return false;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top