1
我想創建一個顯示地圖的活動。當我點擊一個按鈕時,我將一個LatLng點保存到列表中。所以我走在街上,走路時,我點擊按鈕,我想在地圖上顯示我的路線。所以我嘗試寫下這段代碼但未找到:如何在地圖上顯示路線
public void settaMappa(View view){
LocationResult locationResult = new LocationResult(){
@Override
public void gotLocation(Location location){
//Got the location!
System.out.println("ho avuto un segnale gps valido ");
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2)).getMap();
if(listaPuntiTerreno == null)
listaPuntiTerreno = new ArrayList<LatLng>();
if (location != null)
{
LatLng latLong = new LatLng(location.getLatitude(), location.getLongitude());
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLong, 13));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(40) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
listaPuntiTerreno.add(latLong);
disegnaTracciato();
}
}
};
MyLocation myLocation = new MyLocation();
myLocation.getLocation(this, locationResult);
}
public void disegnaTracciato(){
if(listaPuntiTerreno !=null &&
listaPuntiTerreno.size()>1){
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2)).getMap();
PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
for (int z = 0; z < listaPuntiTerreno.size(); z++) {
LatLng point = listaPuntiTerreno.get(z);
options.add(point);
}
Polyline line = mMap.addPolyline(options);
}
}
我們可以幫我嗎?
最佳reguards
實際上你的問題是什麼? – 2014-10-10 09:42:49
想要用您的特定路線動畫您的當前位置? – Piyush 2014-10-10 09:44:36
問題是這樣的:當我把地圖PolylineOptions放入地圖時,我沒有在地圖上看到輪廓。 – bircastri 2014-10-10 10:10:12