How to add marker on google maps android?

后端 未结 5 2030
一向
一向 2021-01-01 13:20

I am a beginner in Android programming. I already looked at similar questions and answers but I still can\'t figure out why this doesn\'t work. When I try this on the emulat

5条回答
  •  一生所求
    2021-01-01 13:52

    Look here in Google Maps example https://developers.google.com/maps/documentation/android-api/marker

    If you want to add marker when clicking you can also look here: http://wptrafficanalyzer.in/blog/adding-marker-on-touched-location-of-google-maps-using-android-api-v2-with-supportmapfragment/

    The concept is to do like the folowing code:

    // Setting a click event handler for the map
        googleMap.setOnMapClickListener(new OnMapClickListener() {
    
            @Override
            public void onMapClick(LatLng latLng) {
    
                // Creating a marker
                MarkerOptions markerOptions = new MarkerOptions();
    
                // Setting the position for the marker
                markerOptions.position(latLng);
    
                // Setting the title for the marker.
                // This will be displayed on taping the marker
                markerOptions.title(latLng.latitude + " : " + latLng.longitude);
    
                // Clears the previously touched position
                googleMap.clear();
    
                // Animating to the touched position
                googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
    
                // Placing a marker on the touched position
                googleMap.addMarker(markerOptions);
            }
        });
    

提交回复
热议问题