【问题标题】:How do I move the google map?如何移动谷歌地图?
【发布时间】:2011-11-13 18:42:43
【问题描述】:

我正在使用 Google Maps API 为 Android 创建一个应用程序。我加载地图以定位我的位置,但我遇到了问题。当我移动到另一个位置时,我立即返回我在屏幕中心的位置。我宁愿地图保持在我移动的地方。

这是我的代码:

private void setCurrentLocation(Location location)
{               
    if(location != null)
    {
        // Aggiorna la location
        Lat = location.getLatitude();
        Long = location.getLongitude();

        int latitudeE6 = (int) Math.floor(Lat * 1.0E6);
        int longitudeE6 = (int) Math.floor(Long * 1.0E6);

        GeoPoint p1 = new GeoPoint(latitudeE6, longitudeE6);
        GeoPoint p2 = new GeoPoint(currentLatitude, currentLongitude);

        // Aggiorna la posizione corrente
        currentLatitude = latitudeE6;
        currentLongitude = longitudeE6;

        // Sposta la posizione corrente sulla mappa di F_Map
        F_Map.mapController.setCenter(p1);

        // Calcola i metri appena fatti
        float dist = Distance.getDistance(p1, p2) *1000;

        if(dist > 1) // maggiore di 1 metro
        {                               
             Toast.makeText(getApplicationContext(), "distance: "+dist,Toast.LENGTH_SHORT).show();

             try 
             {
                 SendMyPositionToDB(currentLatitude, currentLongitude);
             } catch(IOException e) {
                 e.printStackTrace();
             }                               
        }
    }
}

【问题讨论】:

    标签: android google-maps maps


    【解决方案1】:

    你能设置吗:

    F_Map.mapController.setCenter(p2);
    

    而不是 p1?

    【讨论】:

    • 问题不在于坐标。现在,每次 GPS 检测到移位时地图都会移动(map.setCenter ();在 onChangeLocation () 中)。我想确保当您触摸屏幕时,setCenter 被禁用,然后在您按下特殊按钮时重新激活。
    猜你喜欢
    • 2011-01-30
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多