2017-09-25 2 views
0

Google지도에서 몇 가지 사항을 보여주고 있습니다. 첫 번째로드에서 표시 할 수 있습니다. onMapReady 함수를 사용합니다.안드로이드에서 새로운 좌표로지도 마커를 다시 그릴 수있는 방법

@Override 
    public void onMapReady(GoogleMap googleMap) { 
     map = googleMap; 
     if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
      return; 
     } 
     map.setMyLocationEnabled(true); 
     LatLng driver_point = new LatLng(driver_latitude, driver_longitude); 
     LatLng pickup_point = new LatLng(pickup_latitude, pickup_longitude); 
     LatLng drop_point = new LatLng(drop_latitude, drop_longitude); 

     LatLngBounds.Builder builder = new LatLngBounds.Builder(); 
     if (driver_point.latitude != 0.0) 
      builder.include(driver_point); 
     builder.include(pickup_point); 
     builder.include(drop_point); 

     LatLngBounds bounds = builder.build(); 

     int width = getResources().getDisplayMetrics().widthPixels; 
     int height = getResources().getDisplayMetrics().heightPixels; 
     int padding = (int) (width * 0.10); 

     CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding); 

     map.animateCamera(cu); 
     if (driver_point.latitude != 0.0) 
      markerPoints.add(driver_point); 
     markerPoints.add(pickup_point); 
     markerPoints.add(drop_point); 

     // Creating MarkerOptions 
     MarkerOptions driver_opt = new MarkerOptions(); 
     // Setting the position of the marker 
     driver_opt.position(driver_point); 
     driver_opt.icon(BitmapDescriptorFactory.fromResource(R.drawable.car_tiny)); 
     map.addMarker(driver_opt); 

     // Creating MarkerOptions 
     MarkerOptions pickup_opt = new MarkerOptions(); 
     // Setting the position of the marker 
     pickup_opt.position(pickup_point); 
     pickup_opt.icon(BitmapDescriptorFactory.fromResource(R.drawable.pickup_icon)); 
     map.addMarker(pickup_opt); 

     MarkerOptions drop_opt = new MarkerOptions(); 
     // Setting the position of the marker 
     drop_opt.position(drop_point); 
     drop_opt.icon(BitmapDescriptorFactory.fromResource(R.drawable.dropoff_icon)); 
     map.addMarker(drop_opt); 
    } 

서버 호출 후 마커를 새로운 것으로 업데이트하려고합니다. 어떻게하면 될까요? 미리 감사드립니다.

+1

myMarker.setPosition (newLatLng); – james

답변

0

함수를 만들고 새 함수를 전달합니다. 이전 마커를 지우려면 map.clear()를 호출하기 만하면됩니다.

public void drawmap(LatLng newlatlng) 
{ 
    map.clear(); 
    map.addMarker(new MarkerOptions().position(newlatlng).title("Marker in ??")); 
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(newlatlng,15.0f)); 
} 
0

기본 (빨간색) 마커가 여러 개있을 수 있습니다.

LatLng coordinate1 = new LatLng(latitude1, longitude1); 

CameraUpdate yourLocation1 = CameraUpdateFactory.newLatLngZoom(coordinate1,15); 

mMap.animateCamera(yourLocation1); 

/// 

LatLng coordinate2 = new LatLng(latitude2, longitude2); 

CameraUpdate yourLocation2 = CameraUpdateFactory.newLatLngZoom(coordinate2,15); 

mMap.animateCamera(yourLocation2); 

/// 

LatLng coordinate3 = new LatLng(latitude3, longitude3); 

CameraUpdate yourLocation3 = CameraUpdateFactory.newLatLngZoom(coordinate3,15); 

mMap.animateCamera(yourLocation3);