Android 使用Google Maps API v2以文本形式获取当前位置
我目前正在我的应用程序中检索当前位置,但我还需要该位置的文本,或者至少我所在的城市,类似的内容 有什么已知的方法可以做到这一点吗 这就是我到目前为止所做的:Android 使用Google Maps API v2以文本形式获取当前位置,android,google-maps,android-maps,android-maps-v2,mapfragment,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.LocationManag
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);
}
}
首先,您必须获取当前的
纬度
和经度
,然后您可以使用谷歌api
获取当前地址组件。查看我对这个问题的回答,从lat long
您可能想查看并使用getFromLocation()方法?是的,这正是我想要的,非常感谢!好东西-如果这是你想要的答案,再加上它?我没有足够的声誉:)哈!好的,谢谢你的尝试/思考。祝你好运。很好的解决方案,我最终使用了类似的东西!非常感谢。