使用Google Maps API v2获取当前位置为TEXT

时间:2013-07-31 08:10:43

标签: android google-maps android-maps android-maps-v2 mapfragment

我目前正在我的应用中检索当前位置,但我还需要此位置的文字,或者至少我所在的城市,就像这样。

有没有任何已知的方法可以做到这一点?

这是我到目前为止所做的:

package ro.gebs.captoom.activities;

import android.app.Activity;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Window;

import com.example.captoom.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class LocationActivity extends Activity {

    private GoogleMap map;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        getActionBar().hide();
        setContentView(R.layout.preview_location);

        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();

        LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = service.getBestProvider(criteria, false);
        Location location = service.getLastKnownLocation(provider);
        LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude());


        if (map != null) {
            Marker current_location_marker = map.addMarker(new MarkerOptions().position(userLocation)
                      .title("Current Location"));
        } else {

        }

        map.moveCamera(
                CameraUpdateFactory.newLatLngZoom(userLocation, 10));

        // Zoom in, animating the camera.
        map.animateCamera(
                CameraUpdateFactory.zoomTo(10), 2000, null);

    }

}

1 个答案:

答案 0 :(得分:1)

首先,您必须获取当前的latitudelongitude,然后才能使用google api获取当前地址组件。请参阅我对此问题的回答,以便从address

获取lat long

Get the particular address using latitude and longitude