protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_customer);
mapFragment = ( SupportMapFragment ) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
Log.d(TAG, "GoogleMap is ready.");
map = googleMap;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
map.setMyLocationEnabled(true);
}
});
try {
MapsInitializer.initialize(this);
} catch(Exception e) {
e.printStackTrace();
}
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
requestMyLocation();
}
});
}
Do it! 안드로이드 앱 프로그래밍 책으로 공부중인데
책 내용에서는 map.setMyLocationEnabled(ture); 코드를 그냥 사용해도 별 문제 없이 프로그램이 작동하는데
제가 직접 해보면 해당 부분에서 에러가 발생하더라구요.
Add permission Check 이런 내용이 나오는데
permission Check 를 추가해주면 또
if (ActivityCompat.checkSelfPermission(this
이부분에서 incompatible types: <anonymous OnMapReadyCallback> cannot be converted to Context
라는 에러가 발생합니다.
이런 경우에는 어찌해줘야 하나요?ㅠ