Google Maps Android V2 でルート検索2
・・・・・・・ import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks; import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener; import com.google.android.gms.location.LocationClient; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.maps.model.CameraPosition; public class MainActivity extends FragmentActivity implements OnConnectionFailedListener, LocationListener, ConnectionCallbacks { GoogleMap gMap; private LocationClient mLocationClient = null; private static final LocationRequest REQUEST = LocationRequest.create() .setInterval(5000) .setFastestInterval(16) .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); LocationManager locationManager; String provider; SupportMapFragment mapfragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mapfragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); gMap = mapfragment.getMap(); //ノーマル gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); gMap.setMyLocationEnabled(true); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); mLocationClient = new LocationClient(getApplicationContext(), this, this); if (mLocationClient != null) { mLocationClient.connect(); } } @Override public void onPause(){ super.onPause(); if (locationManager != null) { mLocationClient.disconnect(); } } @Override public void onLocationChanged(Location location) { // 現在地に移動 CameraPosition cameraPos = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())).zoom(17.0f) .bearing(0).build(); gMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos)); } @Override public void onConnectionFailed(ConnectionResult result) { // TODO Auto-generated method stub } @Override public void onConnected(Bundle connectionHint) { // TODO Auto-generated method stub mLocationClient.requestLocationUpdates(REQUEST,this); // LocationListener } @Override public void onDisconnected() { // TODO Auto-generated method stub } }