구글맵 에서 마커를 여러개 생성하고 말풍선을 항상 띄워놓기 위해 showInfoWindow() 를 사용했습니다.
그런데 마지막에 실행된 마커 하나만 말풍선이 나타나고 나머지는 사라집니다.
여러개의 마커에 모두 동시에 말풍선을 띄우는 방법은 없나요ㅜㅜ
public class FindMartActivity extends AppCompatActivity implements OnMapReadyCallback{
private GoogleMap googleMap;
private Marker curMarker;
private LatLng point = new LatLng(36.83456344318653, 127.17946583991449);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_mart);
MapFragment mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
try {
MapsInitializer.initialize(this);
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
public void onMapReady(GoogleMap map) {
googleMap = map;
showAllMart();
startLocationService();
}
private void startLocationService() {
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
GPSListener gpsListener = new GPSListener();
long minTime = 10000;
float minDistance = 0;
try {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
minTime,
minDistance,
gpsListener
);
Location lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(lastLocation != null) {
Double latitude = lastLocation.getLatitude();
Double longitude = lastLocation.getLongitude();
Toast.makeText(getApplicationContext(), "Last Known Location: " + "Latitude: " + latitude + "\nLongitude: " + longitude, Toast.LENGTH_SHORT).show();
curMarker = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("최근 위치")
);
curMarker.showInfoWindow();
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 13), 2000, null);
}
}catch(SecurityException ex) {
System.out.println(ex.getMessage());
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}
Toast.makeText(getApplicationContext(), "위치확인이 시작됨, 로그확인", Toast.LENGTH_SHORT).show();
}
private class GPSListener implements LocationListener {
public void onLocationChanged(Location location) {
Double latitude = location.getLatitude();
Double longitude = location.getLongitude();
String msg = "Latitude: " + latitude + "\nLongitude: " + longitude;
Log.i("GPSLocationService", msg);
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
showCurrentLocation(latitude, longitude);
//showCurrentLocation(36.83456344318653, 127.17946583991449);
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
private void showCurrentLocation(Double latitude, Double longitude) {
LatLng curPoint = new LatLng(latitude, longitude);
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(curPoint, 13), 2000, null);
curMarker.remove();
curMarker = googleMap.addMarker(new MarkerOptions()
.position(curPoint)
.title("현 위치")
);
curMarker.showInfoWindow();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
//showAllMart();
}
private void showAllMart() {
Marker aMarker, bMarker, cMarker;
LatLng amartPoint = new LatLng(36.8196850, 127.1543900);
LatLng bmartPoint = new LatLng(36.7991010, 127.1655390);
LatLng cmartPoint = new LatLng(36.8262460, 127.1400880);
aMarker = googleMap.addMarker(new MarkerOptions()
.position(amartPoint)
.title("A 마트")
);
aMarker.showInfoWindow();
bMarker = googleMap.addMarker(new MarkerOptions()
.position(bmartPoint)
.title("B 마트")
);
bMarker.showInfoWindow();
cMarker = googleMap.addMarker(new MarkerOptions()
.position(cmartPoint)
.title("C 마트")
);
cMarker.showInfoWindow();
}
public void onBackPressed() {
super.onBackPressed();
}
}