17 Ocak 2017 Salı

Google-Maps GoogleMap.OnMapReadyCallback Arayüzü

Giriş
Şu satırı dahil ederiz.
import com.google.android.gms.maps.OnMapReadyCallback;
GoogleMap ile gelen SupportMapFragment kullanarak şöyle yaparız.
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_maps);
  // Obtain the SupportMapFragment and get notified 
     when the map is ready to be used.
  SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    new GetAddress().execute();
}
onMapReady metodu
Şöyle yaparız
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

public GoogleMap mMap;
...


  @Override
  public void onMapReady(GoogleMap googleMap) {

    mMap = googleMap;
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    if (ContextCompat.checkSelfPermission(this,
      Manifest.permission.ACCESS_FINE_LOCATION)
        == PackageManager.PERMISSION_GRANTED) {
    mMap.setMyLocationEnabled(true);
  }
    mMap.getUiSettings().setCompassEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(true);
  ...
  }
...
}

Hiç yorum yok:

Yorum Gönder