GMapCamera
GMapCamera
문제
초기화면
CCTV 클릭시
MapsActivity.java
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import kr.ac.skuniv.a1204practice_2.databinding.ActivityMapsBinding;
public class MapsActivity extends FragmentActivity implements GoogleMap.OnMarkerClickListener,OnMapReadyCallback {
private static final LatLng CAMERA1 = new LatLng(37.63717057, 127.0270418); // LatLng 클래스는 위/경도 좌표를 정의
private static final LatLng CAMERA2 =new LatLng(37.65154554, 127.0122203);
private static final LatLng CAMERA3 =new LatLng(37.612849, 127.034268);
private Marker mCAMERA1;
private Marker mCAMERA2;
private Marker mCAMERA3;
private GoogleMap mMap;
@Override
protected 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);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mCAMERA1 = mMap.addMarker(new MarkerOptions()
.position(CAMERA1)
.title("CAMERA1")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.cctv)));
mCAMERA1.setTag(0);
mCAMERA2 = mMap.addMarker(new MarkerOptions()
.position(CAMERA2)
.title("CAMERA2")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.cctv)));
mCAMERA2.setTag(0);
mCAMERA3 = mMap.addMarker(new MarkerOptions()
.position(CAMERA3)
.title("CAMERA3")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.cctv)));
mCAMERA3.setTag(0);
mMap.setOnMarkerClickListener((GoogleMap.OnMarkerClickListener) this);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(CAMERA1,14));
}
@Override
public boolean onMarkerClick(final Marker marker) {
Integer clickCount = (Integer) marker.getTag();
if (clickCount !=null) {
clickCount = clickCount +1;
marker.setTag(clickCount);
Toast.makeText(this, "카메라 번호 : "+ marker.getTitle(), Toast.LENGTH_SHORT).show();
}
return false;
}
}