标记在谷歌地图为Android

时间:2015-07-07 10:56:15

标签: android xml google-maps google-maps-markers

我想知道如何设置" OnClick "在Android中谷歌地图上的标记

示例:用户触摸标记,我的应用程序会检测到此标记。

我的标记

 @Override
    public void onMapReady(GoogleMap map) {
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(-18.142, 178.431), 2));
        map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        map.setMyLocationEnabled(true);
        mUiSettings = map.getUiSettings();

        mUiSettings.setZoomControlsEnabled(true);
        LatLng sydney = new LatLng(-33.867, 151.206);

        map.setMyLocationEnabled(true);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));

        map.addMarker(new MarkerOptions()
                .title("Sydney")
                .snippet("The most populous city in Australia.")
                .position(sydney));
    }

3 个答案:

答案 0 :(得分:1)

尝试使用OnMarkerClickListener,如下所示:

map.setOnMarkerClickListener(new OnMarkerClickListener(){

            @Override
            public boolean onMarkerClick(Marker arg0) {
                // do your stuff
                return true;
            }});

答案 1 :(得分:0)

implement OnMarkerClickListener

public class MarkerDemoActivity extends android.support.v4.app.FragmentActivity
        implements OnMarkerClickListener
    {
        private Marker myMarker;    

            myMarker = googleMap.addMarker();
        }

        @Override
        public boolean onMarkerClick(final Marker marker) {

            if (marker.equals(myMarker)) 
            {
                //handle click here
            }
        }
    }

答案 2 :(得分:0)

示例

this.googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {                       
                            @Override
                            public boolean onMarkerClick(Marker arg0) {
                                Log.d(TAG, arg0.getTitle() + " | " + arg0.getPosition().toString());            
                                return false;
                            }
                        });