我正在使用谷歌地图开发应用程序我已成功获取当前位置但我无法直接转到我的位置。我想在打开我的应用程序时转到我当前位置并从该位置添加一些圈子请告诉我如何它是
我的代码
public class MainActivity extends FragmentActivity {
GoogleMap _googleMap;
LatLng myPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_googleMap = ((SupportMapFragment)
getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
if(_googleMap==null){
Toast.makeText(getApplicationContext(), "Google Map Not Available",
Toast.LENGTH_LONG).show();
}
LocationManager locationManger =
(LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria=new Criteria();
String provider = locationManger.getBestProvider(criteria, true);
Location location = locationManger.getLastKnownLocation(provider);
if(location!=null){
double latitude = location.getLatitude();
double langitude = location.getLongitude();
LatLng latlang = new LatLng(latitude, langitude);
LatLngBounds curScreen =
_googleMap.getProjection().getVisibleRegion().latLngBounds;
curScreen.contains(latlang);
myPosition = new LatLng(latitude, langitude);
_googleMap.addMarker(new
MarkerOptions().position(myPosition).title("start"));
}
}