2017-09-25 9 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); 
関連する問題