Code example for Marker

Methods: getPositionsetSnippetshowInfoWindow

0
        super.onDestroy(); 
    } 
 
    public boolean onMarkerClick(Marker marker) {
        updateMarkerDistance(marker);
        marker.showInfoWindow();
 
        return true; 
    } 
 
    public void updateMarkerDistance(Marker marker) {
        if (map.getMyLocation() == null) {
 
            marker.setSnippet("");
 
        } else { 
 
            float[] results = new float[1];
 
            Location.distanceBetween(map.getMyLocation().getLatitude(), map.getMyLocation().getLongitude(),
                    marker.getPosition().latitude, marker.getPosition().longitude, results);
 
            double distance = results[0];
 
            if (distance < 2000) {
                marker.setSnippet(String.format("Afstand: %.0f m", results[0]));
            } else { 
                marker.setSnippet(String.format("Afstand: %.1f km", results[0] / 1000.0));
            } 
 
 
        } 
    } 
Experience pair programming with AI  Get Codota for Java