2014-09-15 3 views
0

Я новичок в Android. Я пытаюсь сделать проект MAP .. Я нахожу код из какого-то блога, и я его редактирую с тем, как это работает, но в то же время, и Output просто продолжают делать progressDialog ... никогда не заканчиваютсяGoogle Map V2 API Направления: нет ошибки, но не очень хорошо

это мой код

public class LokasiActivity extends FragmentActivity{ 

public static final String USER_CURRENT_LAT = "user_current_lat"; 
public static final String USER_CURRENT_LONG = "user_current_long"; 
public static final String DESTINATION_LAT = "destination_lat"; 
public static final String DESTINATION_LONG = "destination_long"; 
public static final String DIRECTIONS_MODE = "directions_mode"; 
private static final LatLng AMSTERDAM = new LatLng(52.37518, 4.895439); 
private static final LatLng PARIS = new LatLng(48.856132, 2.352448); 
private Exception exception; 
private ProgressDialog progressDialog; 
private GoogleMap googleMap; 
Button btnjalur; 
ArrayList<LatLng> directionPoints; 
SupportMapFragment fragment; 
private Polyline newPolyline; 
private int width, height; 
private LatLngBounds latlngBounds; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.lokasi_layout); 

    btnjalur = (Button)findViewById(R.id.btnJalur); 

    getSreenDimanstions(); 

     fragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)); 
     googleMap = fragment.getMap(); 

    btnjalur.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 

      findDirections(AMSTERDAM.latitude, AMSTERDAM.longitude, PARIS.latitude, PARIS.longitude, LokasiDirection.MODE_DRIVING); 

     } 
    }); 
} 


public void handleGetDirectionsResult() { 
    PolylineOptions rectLine = new PolylineOptions().width(5).color(Color.RED); 

    for(int i = 0 ; i < directionPoints.size() ; i++) 
    {   
     rectLine.add(directionPoints.get(i)); 
    } 
    if (newPolyline != null) 
    { 
     newPolyline.remove(); 
    } 
    newPolyline = googleMap.addPolyline(rectLine); 

     latlngBounds = createLatLngBoundsObject(AMSTERDAM, PARIS); 
     googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(latlngBounds, width, height, 150)); 


} 

private void getSreenDimanstions() 
{ 
    Display display = getWindowManager().getDefaultDisplay(); 
    width = display.getWidth(); 
    height = display.getHeight(); 
} 

private LatLngBounds createLatLngBoundsObject(LatLng firstLocation, LatLng secondLocation) 
{ 
    if (firstLocation != null && secondLocation != null) 
    { 
     LatLngBounds.Builder builder = new LatLngBounds.Builder();  
     builder.include(firstLocation).include(secondLocation); 

     return builder.build(); 
    } 
    return null; 
} 

public class GetDirectionsAsyncTask extends AsyncTask<Map<String, String>, Object, ArrayList<LatLng>> 
{ 

    public void onPreExecute() 
    { 
     progressDialog = new ProgressDialog(LokasiActivity.this); 
     progressDialog.setMessage("Calculating directions"); 
     progressDialog.show(); 
    } 


    @Override 
    protected ArrayList<LatLng> doInBackground(Map<String, String>... params) 
    { 
     Map<String, String> paramMap = params[0]; 
     try 
     { 
      LatLng fromPosition = new LatLng(Double.valueOf(paramMap.get(USER_CURRENT_LAT)) , Double.valueOf(paramMap.get(USER_CURRENT_LONG))); 
      LatLng toPosition = new LatLng(Double.valueOf(paramMap.get(DESTINATION_LAT)) , Double.valueOf(paramMap.get(DESTINATION_LONG))); 
      LokasiDirection md = new LokasiDirection(); 
      Document doc = md.getDocument(fromPosition, toPosition, paramMap.get(DIRECTIONS_MODE)); 
      directionPoints = md.getDirection(doc); 
      return directionPoints; 
     } 
     catch (Exception e) 
     { 
      exception = e; 
      return null; 
     } 
    } 

    public void onPostExecute() 
    { 
     progressDialog.dismiss(); 
     if (exception == null) 
     { 
      handleGetDirectionsResult(); 
     } 
     else 
     { 
      processException(); 
     } 
    } 


    private void processException() 
    { 
     Toast.makeText(LokasiActivity.this, "Error retriving data", 3000).show(); 
    } 
} 

public void findDirections(double fromPositionDoubleLat, double fromPositionDoubleLong, double toPositionDoubleLat, double toPositionDoubleLong, String mode) 
{ 
    Map<String, String> resultdestination = new HashMap<String, String>(); 
    resultdestination.put(USER_CURRENT_LAT, String.valueOf(fromPositionDoubleLat)); 
    resultdestination.put(USER_CURRENT_LONG, String.valueOf(fromPositionDoubleLong)); 
    resultdestination.put(DESTINATION_LAT, String.valueOf(toPositionDoubleLat)); 
    resultdestination.put(DESTINATION_LONG, String.valueOf(toPositionDoubleLong)); 
    resultdestination.put(DIRECTIONS_MODE, mode); 

    new GetDirectionsAsyncTask().execute(resultdestination); 
} 
@Override 
protected void onResume() { 
    super.onResume(); 
    latlngBounds = createLatLngBoundsObject(AMSTERDAM, PARIS); 
    googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latlngBounds, width, height, 150)); 


} 

}

есть что-то случилось с моим кодом .... пожалуйста, скажите мне, если и понимают, что ..

ответ

0

выхода просто продолжать делать progressDialog ... никогда не закончится

Вы никогда не отключаете диалог прогресса. Код в onPostExecute() никогда не выполняется, поскольку подпись метода неверна.

Изменить

public void onPostExecute() 

в

@Override 
public void onPostExecute(ArrayList<LatLng> result) 

@Override аннотацию помогает компилятору убедиться, что вы на самом деле перекрытый метод, испуская ошибку в случае, если вы не.

 Смежные вопросы

  • Нет связанных вопросов^_^