Как мне переместить карту Google? - PullRequest
0 голосов
/ 13 ноября 2011

Я делаю приложение для Android, используя Google Maps API. Я загружаю карту, чтобы определить свою позицию, но у меня проблема. Когда я перехожу в другое место, я немедленно возвращаю свою позицию по центру экрана. Я бы предпочел, чтобы карта оставалась в том месте, куда я переместился.

Вот мой код:

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();
             }                               
        }
    }
}

1 Ответ

0 голосов
/ 13 ноября 2011

Можете ли вы установить:

F_Map.mapController.setCenter(p2);

вместо р1?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...