2017-04-18 9 views
0

屋内マップが必要なAndroidアプリプロジェクトに取り組んでいます。私が使っている場所には、Googleマップで利用可能なフロアがあります。私はGoogle Maps Android APIを使用しています。私はマーカーを最初のレベルに設定しました。フロアを切り替えると、これらのマーカーを削除/非表示にして新しいマーカーに置き換えることはできますか?ここ は私のJavaコードです:Google Maps Android API床を切り替えるときのマーカーの削除

package com.me.maps; 

import android.support.v4.app.FragmentActivity; 
import android.os.Bundle; 

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.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    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); 
    } 



    /** 
    * Manipulates the map once available. 
    * This callback is triggered when the map is ready to be used. 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
    * we just add a marker near Milwaukee, Wisconsin. 
    * If Google Play services is not installed on the device, the user will be prompted to install 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
    * installed Google Play services and returned to the app. 
    */ 
    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     // Add a marker in Sydney and move the camera 
     LatLng mpm = new LatLng(43.0408468, -87.921474); 
     LatLng planetarium = new LatLng(43.040622,-87.920798); 
     LatLng theater = new LatLng(43.040497,-87.920640); 
     LatLng marketplace = new LatLng(43.040779,-87.921717); 
     mMap.addMarker(new MarkerOptions().position(mpm).title("Milwaukee Public Museum")); 
     mMap.addMarker(new MarkerOptions().position(planetarium).title("The Daniel M. Soref National Geographic Planetarium")); 
     mMap.addMarker(new MarkerOptions().position(theater).title("The Daniel M. Soref National Geographic Theater")); 
     mMap.addMarker(new MarkerOptions().position(marketplace).title("Museum Marketplace")); 
     mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mpm, 18)); 
    } 
} 

答えて

0
//Place current location marker 
    latitude = location.getLatitude(); 
    longitude = location.getLongitude(); 
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); 
    MarkerOptions markerOptions = new MarkerOptions(); 
    markerOptions.position(latLng); 
    markerOptions.title("Current Position"); 
    BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.doctor); 
    markerOptions.icon(icon); 
    mCurrLocationMarker = mMap.addMarker(markerOptions); 

    //move map camera 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 
    mMap.animateCamera(CameraUpdateFactory.zoomTo(11)); 

変更マーカーのアイコンに使用し、このコードを使用します。

+0

返信いただきありがとうございます。私はこれがどこに行くのか分からない。私はそれをonMapReady()に追加し、エラーを示しました。これを実装する方法はありますか?これは床のセレクタボタンに付ける必要がありますか? –

+0

フロアセレクターボタンをクリックすると、作成されたマーカーを@hereでクリアするだけです。 '' 'markerOptions.clear()' '' –

0

フロアを切り替えると、マップ上のマーカーがクリアされます。 Googleマップインスタンスの.clear()メソッドを使用し、そのフロアに関連するマーカーのみを追加します。

このメソッドのドキュメントを見つけることができます:https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap

はそれがお役に立てば幸いです。

+0

.clear()をどこに添付するのか探しがたいです。私はドキュメントを見ていて、フロアセレクタへの唯一の参照は次のとおりです:setIndoorLevelPickerEnabled(true);イベントリスナーか、自分のコードに追加する必要があるものは何ですか?私はどこに見えるのか分からない。私はそれらの特定のボタンをクリックすることに何かを追加する方法への参照が表示されません。 –

関連する問題