1
      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 个标记,例如源和目标,我使用了上面的代码,当我运行应用程序时,我得到一条黑线,显示源和目标之间的路线,但标记没有出现在地图上:( 有人能帮我吗?

4

1 回答 1

2

试试这个代码

public void drawMarker(LatLng source_point,LatLong destination_point) {

    // Creating an instance of MarkerOptions
    MarkerOptions markerOptions1 = new MarkerOptions();
    markerOptions1.title("Marker");
    markerOptions1.snippet("Marker Yo Yo");
    markerOptions1.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
    markerOptions1.position(source_point);

    MarkerOptions markerOptions2 = new MarkerOptions();
    markerOptions2.title("Marker2");
    markerOptions2.snippet("Marker Xo Xo");
    markerOptions2.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
    markerOptions2.position(destination_point);

    // Adding marker on the Google Map

    map.addMarker(markerOptions1);
    map.addMarker(markerOptions2);
}
于 2013-09-05T06:43:23.383 回答