Android 构造函数的地质点(双精度,双精度)未定义。什么';怎么了?

Android 构造函数的地质点(双精度,双精度)未定义。什么';怎么了?,android,Android,我有一个错误:“构造器地质点(双精度,双精度)未定义”。为什么会这样?如何做对?据我所知,有所有必要的库链接和语法似乎是正确的 package com.fewpeople.geoplanner; import android.app.Activity; import android.os.Bundle; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com

我有一个错误:“构造器地质点(双精度,双精度)未定义”。为什么会这样?如何做对?据我所知,有所有必要的库链接和语法似乎是正确的

package com.fewpeople.geoplanner;

import android.app.Activity;
import android.os.Bundle;

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

public class GeoplannerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final MapView mMapView = (MapView) findViewById(R.id.mapview);

     MapController mMapController = mMapView.getController();

     double x, y;
     x= 60.113337;
     y= 55.151317;

     mMapController.animateTo(new GeoPoint(x, y));

     mMapController.setZoom(15);

    }

    protected boolean isRouteDisplayed() {
        return false;
    }
}

java不会自动将double转换为int(数据丢失等),GeoPoint的唯一构造函数接受2个int。所以写下:

mMapController.animateTo(new GeoPoint((int)x, (int)y));

或者首先将点声明为int。

java不会自动将double转换为int(数据丢失等),并且GeopPoint的唯一构造函数接受2个int。所以写下:

mMapController.animateTo(new GeoPoint((int)x, (int)y));

或者首先将点声明为整数。

GeoPoint接受两个以微度为坐标的整数。为了简单起见,我使用此方法:

/**
 * Converts a pair of coordinates to a GeoPoint
 * 
 * @param coords double containing latitude and longitude
 * @return GeoPoint for the same coords
 */
public static GeoPoint coordinatesToGeoPoint(double[] coords) {
    if (coords.length > 2) {
        return null;
    }
    if (coords[0] == Double.NaN || coords[1] == Double.NaN) {
        return null;
    }
    final int latitude = (int) (coords[0] * 1E6);
    final int longitude = (int) (coords[1] * 1E6);
    return new GeoPoint(latitude, longitude);
}

此外,您的活动应该扩展MapActivity。

GeoPoint接受两个以微度为坐标的整数。为了简单起见,我使用此方法:

/**
 * Converts a pair of coordinates to a GeoPoint
 * 
 * @param coords double containing latitude and longitude
 * @return GeoPoint for the same coords
 */
public static GeoPoint coordinatesToGeoPoint(double[] coords) {
    if (coords.length > 2) {
        return null;
    }
    if (coords[0] == Double.NaN || coords[1] == Double.NaN) {
        return null;
    }
    final int latitude = (int) (coords[0] * 1E6);
    final int longitude = (int) (coords[1] * 1E6);
    return new GeoPoint(latitude, longitude);
}

此外,您的活动还应该扩展MapActivity。

整理了Ian G.Clifton的尼斯实用程序方法,该方法似乎过于冗长:

/**
 * Converts a pair of coordinates to a GeoPoint
 * 
 * @param lat double containing latitude
 * @param lng double containing longitude
 *            
 * @return GeoPoint for the same coords
 */
public static GeoPoint coordinatesToGeoPoint(double lat, double lgn) {
    return new GeoPoint((int) (lat * 1E6), (int) (lgn * 1E6));
}

整理了Ian G.Clifton的漂亮实用方法,该方法似乎过于冗长:

/**
 * Converts a pair of coordinates to a GeoPoint
 * 
 * @param lat double containing latitude
 * @param lng double containing longitude
 *            
 * @return GeoPoint for the same coords
 */
public static GeoPoint coordinatesToGeoPoint(double lat, double lgn) {
    return new GeoPoint((int) (lat * 1E6), (int) (lgn * 1E6));
}

替换。出现新错误“类型MapController中的animateTo(地理点,消息)方法不适用于参数(int,int)”。为什么?我同意伊恩的看法。它更完整了。出现新错误“类型MapController中的animateTo(地理点,消息)方法不适用于参数(int,int)”。为什么?我同意伊恩的看法。它更完整。