Weird behavior of GeoPoint and/or android.maps.Projection when panning a MapView at max zoom level
<p>I've run into a weird problem with points getting offset using the google maps package.</p>

<p>I have a MapView with a route displayed on it.  I noticed that if I zoom all the way in, and then pan around, my route was getting clipped near the edges of the window.  After much debugging of my own code, I discovered that even a simple case like this was enough to repro the issue:</p>

<pre><code>            GeoPoint midPoint = projection.fromPixels(mapView.getWidth()/2, mapView.getHeight()/2);
            GeoPoint nextPoint = new GeoPoint(midPoint.getLatitudeE6(), midPoint.getLongitudeE6());
            pathPaint.setColor(0xFF00FF00);
            projection.toPixels(midPoint, screenPoint);
            canvas.drawCircle(screenPoint.x, screenPoint.y, 5, pathPaint);
            pathPaint.setColor(0xFF0000FF);
            projection.toPixels(nextPoint, screenPoint);
            canvas.drawCircle(screenPoint.x, screenPoint.y, 5, pathPaint);
</code></pre>

<p>This uses the Projection class returned by MapView.getProjection() to translate pixels coordinates into a GeoPoint.  It then creates a second GeoPoint using the same lat/long.  Finally it translates both of these GeoPoints back into screen coordinates and draws two circles, one on top of the other, at this location.</p>

<p>Except, as you pan around, the second circle gets offset from the first.  They have identical lat/lon coordinates (I check after the drawing), but end up getting translated to different screen coordinates.  My debugging has focused on panning horizontally, but I believe that panning vertically can hit a similar problem, based on what I was seeing with my original app code.</p>

<p>As far as I can tell, any points that are created by the maps package work fine, but any that are created by calling new GeoPoint(lat, lon) exhibit this behavior.</p>

<p>I have created a simple stripped-down application that exhibits this behavior, pasted below.  (Map tiles won't download because I didn't bother to sign it, but you don't need them to see the issue.)  Just launch it, zoom in all the way, and start panning left or right.  Watch the green and blue points diverge, and witness the Log.d prints that state they still have equal lat/lon.</p>

<p>(Is there a better/preferred way for posting sample projects?  Sorry, this is my first posting here.)</p>

<p>src/example/mysample/MapOverlay.java:</p>

<pre><code>package example.mysample;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.view.MotionEvent;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

import android.util.Log;

class MapOverlay extends Overlay
{
    public MapOverlay(MapScreen activity)
    {
        super();

        paint = new Paint();
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setAntiAlias(true);
    }

    @Override public boolean onTouchEvent(MotionEvent e, MapView mapView) {
        int motionAction = e.getAction();
        if ( motionAction == MotionEvent.ACTION_MOVE ) {
            dragging = true;
        }
        if ( motionAction == MotionEvent.ACTION_UP || motionAction == MotionEvent.ACTION_CANCEL ) {
            dragging = false;
        }
        return super.onTouchEvent(e, mapView);
    }

    @Override public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        if (!shadow &amp;&amp; !dragging) {
            Projection projection = mapView.getProjection();

            // Draw two circles at the center
            // One with a virgin point, one that we constructed with the same coordinates
            GeoPoint midPoint = projection.fromPixels(mapView.getWidth()/2, mapView.getHeight()/2);
            GeoPoint nextPoint = new GeoPoint(midPoint.getLatitudeE6(), midPoint.getLongitudeE6());
            paint.setColor(0xFF00FF00);
            projection.toPixels(midPoint, screenPoint);
            canvas.drawCircle(screenPoint.x, screenPoint.y, 5, paint);
            paint.setColor(0xFF0000FF);
            projection.toPixels(nextPoint, screenPoint);
            canvas.drawCircle(screenPoint.x, screenPoint.y, 5, paint);

            // These print EQUAL.
            Log.d("BKC DEBUG", "Midpoint and our own midpoint have " +
                ((midPoint.getLatitudeE6() == nextPoint.getLatitudeE6()) ? "EQUAL" : "UNEQUAL") +
                " latitudes, and " +
                ((midPoint.getLongitudeE6() == nextPoint.getLongitudeE6()) ? "EQUAL" : "UNEQUAL") +
                " longitudes");
        }
    }

    private Paint paint;
    private boolean dragging;
    private Point screenPoint = new Point();

}
</code></pre>

<p>src/example/mysample/MapScreen.java:</p>

<pre><code>package example.mysample;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.util.Log;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.GeoPoint;

public class MapScreen extends MapActivity
{

    @Override public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.map);

        mapView = (MapView)findViewById(R.id.map_map);
        mapView.setBuiltInZoomControls(true);
        mapView.getOverlays().add(new MapOverlay(this));

        MapController controller;
        controller = mapView.getController();
        controller.setZoom(17);
        controller.animateTo(new GeoPoint(36000000, -90000000));

    }

    @Override
    public boolean isRouteDisplayed() {
        return true;
    }

    private MapView mapView;

}
</code></pre>

<p>res/layout/map.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#414141"
    &gt;    

 &lt;com.google.android.maps.MapView
            android:id="@+id/map_map"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="3dip"
            android:layout_marginRight="3dip"
            android:layout_marginTop="3dip"
            android:layout_marginBottom="3dip"
            android:apiKey="0jPQdwUtQGBYfPALki6ghGG_X9Jpf-SllYckR4w"
            android:layout_centerInParent="true"
            android:clickable="true"
            /&gt;

&lt;/RelativeLayout&gt;
</code></pre>

<p>AndroidManifest.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="example.mysample"
      android:versionCode="1"
      android:versionName="2.0.1"&gt;
    &lt;uses-sdk android:minSdkVersion="4" /&gt;

    &lt;!--uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /--&gt;
    &lt;!--uses-permission android:name="android.permission.READ_PHONE_STATE" /--&gt;
    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
    &lt;!--uses-permission android:name="android.permission.WAKE_LOCK" /--&gt;
    &lt;!--uses-permission android:name="android.permission.READ_LOGS" /--&gt;
    &lt;!--uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /--&gt;

    &lt;!--application android:name="src.example.mysample.AppMain"
                 android:label="MySample"
                 android:icon="@drawable/icon_android"
                 android:theme="@android:style/Theme.NoTitleBar"
                 --&gt;

    &lt;application android:name="android.app.Application"
        android:label="MySample" &gt;

        &lt;uses-library android:name="com.google.android.maps"/&gt;

        &lt;!-- Main activity --&gt;
        &lt;activity android:name="example.mysample.MapScreen"
                  android:clearTaskOnLaunch="true"
                  android:label="MySample"
                  android:screenOrientation="portrait"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;

        &lt;!-- Other activities --&gt;
        &lt;!--activity android:name="example.mysample.SomethingElse"
                  android:label="Something"
                  android:screenOrientation="portrait"/--&gt;

    &lt;/application&gt;
&lt;/manifest&gt;
</code></pre>

<p>build.xml (unchanged from template):</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project name="PROJECT_NAME" default="help"&gt;

&lt;!-- The local.properties file is created and updated by the 'android'
     tool.
     It contains the path to the SDK. It should *NOT* be checked into
     Version Control Systems. --&gt;
    &lt;property file="local.properties" /&gt;

    &lt;!-- The build.properties file can be created by you and is never touched
         by the 'android' tool. This is the place to change some of the
         default property values used by the Ant rules.
         Here are some properties you may want to change/update:

         source.dir
             The name of the source directory. Default is 'src'.
         out.dir
             The name of the output directory. Default is 'bin'.

         Properties related to the SDK location or the project target should
         be updated using the 'android' tool with the 'update' action.

         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems.

         --&gt;
    &lt;property file="build.properties" /&gt;

    &lt;!-- The default.properties file is created and updated by the 'android'
         tool, as well as ADT.
         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems. --&gt;
    &lt;property file="default.properties" /&gt;

    &lt;!-- Custom Android task to deal with the project target, and import the
         proper rules.
         This requires ant 1.6.0 or above. --&gt;
    &lt;path id="android.antlibs"&gt;
        &lt;pathelement path="${sdk.dir}/tools/lib/anttasks.jar" /&gt;
        &lt;pathelement path="${sdk.dir}/tools/lib/sdklib.jar" /&gt;
        &lt;pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" /&gt;
    &lt;/path&gt;

    &lt;taskdef name="setup"
        classname="com.android.ant.SetupTask"
        classpathref="android.antlibs" /&gt;

&lt;!-- extension targets. Uncomment the ones where you want to do custom work
     in between standard targets --&gt;
&lt;!--
    &lt;target name="-pre-build"&gt;
    &lt;/target&gt;
    &lt;target name="-pre-compile"&gt;
    &lt;/target&gt;

    [This is typically used for code obfuscation.
     Compiled code location: ${out.classes.absolute.dir}
     If this is not done in place, override ${out.dex.input.absolute.dir}]
    &lt;target name="-post-compile"&gt;
    &lt;/target&gt;
--&gt;


    &lt;!-- Execute the Android Setup task that will setup some properties
         specific to the target, and import the build rules files.

         The rules file is imported from
            &lt;SDK&gt;/platforms/&lt;target_platform&gt;/ant/ant_rules_r#.xml

         To customize existing targets, there are two options:
         - Customize only one target:
             - copy/paste the target into this file, *before* the
               &lt;setup&gt; task.
             - customize it to your needs.
         - Customize the whole script.
             - copy/paste the content of the rules files (minus the top node)
               into this file, *after* the &lt;setup&gt; task
             - disable the import of the rules by changing the setup task
               below to &lt;setup import="false" /&gt;.
             - customize to your needs.
    --&gt;
    &lt;setup /&gt;

&lt;/project&gt;
</code></pre>
