hanchao / MapLite

Android Tile Map, fork from osmdroid
17 stars 3 forks source link

mapview.getController().setCenter does not work as expected #1

Closed apachemaven closed 10 years ago

apachemaven commented 10 years ago

It seems that the GeoPoint passed to the method

 mapview.getController().setCenter()

can not be a integer.

For example, the following code works:

mapview.getController().setCenter(new GeoPoint(30.1, 120.1));

but this does not:

mapview.getController().setCenter(new GeoPoint(30, 120));
hanchao commented 10 years ago

需要说明的是这里内部采用的是整形坐标,单位是微秒。这和Android's MapView (v1 API) 是一样的。

所以这里GeoPoint(30, 120)应该改成GeoPoint(30 * 1E6, 120 * 1E6)

为什么GeoPoint(30.1, 120.1)正确的,你可以看下构造函数的实现。 GeoPoint 有两个构造函数。

public GeoPoint(final int aLatitudeE6, final int aLongitudeE6) {
    this.mLatitudeE6 = aLatitudeE6;
    this.mLongitudeE6 = aLongitudeE6;
}

public GeoPoint(final double aLatitude, final double aLongitude) {
    this.mLatitudeE6 = (int) (aLatitude * 1E6);
    this.mLongitudeE6 = (int) (aLongitude * 1E6);
}