public void onLoad() {
// Opening the sharedPreferences object
preferences = getSharedPreferences("location", 0);
// Getting number of locations already stored
routeType = preferences.getInt("routeType", 0);
// Getting stored zoom level if exists else return 0
String zoom = preferences.getString("zoom", "0");
// If locations are already saved
if (routeType != 0) {
    String lat = "sourceAdd";
    String lng = "destinationAdd";
    // Iterating through all the locations stored
    for (int i = 0; i < routeType; i++) {
        // Getting the latitude of the i-th location
        lat = preferences.getString("lat" + i, "0");
        // Getting the longitude of the i-th location
        lng = preferences.getString("lng" + i, "0");
        // Drawing marker on the map
        drawMarker(new LatLng(Double.parseDouble(lat),
                Double.parseDouble(lng)));
    }
    // Moving CameraPosition to last clicked position
    map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(Double
            .parseDouble(lat), Double.parseDouble(lng))));
    // Setting the zoom level in the map on last position is clicked
    map.animateCamera(CameraUpdateFactory.zoomTo(Float.parseFloat(zoom)));
}
}
公共无效drawMarker(LatLng点){
    // Creating an instance of MarkerOptions
    MarkerOptions markerOptions = new MarkerOptions();
    // Setting latitude and longitude for the marker
    markerOptions.position(point);
    // Adding marker on the Google Map
    map.addMarker(new MarkerOptions()
            // map.addMarker(markerOptions);
            .title("Marker")
            .snippet("Marker Yo Yo")
            .icon(BitmapDescriptorFactory
                    .defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
            .position(point)
    );
}
你好,
我需要在地图上添加 2 个标记,例如源和目标,我使用了上面的代码,当我运行应用程序时,我得到一条黑线,显示源和目标之间的路线,但标记没有出现在地图上:( 有人能帮我吗?