2014-06-02 3 views
0

나는 임의의 행을 누르면 맵의 특정 주소를 표시해야하는 주소의 목록보기가 있습니다. 그 때문에 Geoocder를 사용하여 해당 주소의 위도와 경도를 가져옵니다.목록보기에 지오 코드를 사용하여지도를 표시하는 방법

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

     lvEmployees = (ListView) findViewById(R.id.lvEmployees); 


     lvEmployees.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> adapter, View v, 
       int position, long id) { 

      String address; 
      Geocoder coder = new Geocoder(getApplicationContext()); 
      List<Address> address1; 


      // If Google Play Services is available 


      // Display Selected Row of Listview into EditText widget 

      Cursor row = (Cursor) adapter.getItemAtPosition(position); 
      try { 
       String strAddress=row.getString(0)+" "+row.getString(2); 
       System.out.println("strAddress>>>"+strAddress); 
       address1 = coder.getFromLocationName(strAddress,5); 

       Address location = address1.get(0); 

       latitude= location.getLatitude(); 
       longitude= location.getLongitude(); 

      } 
      catch(Exception e){ 
      } 
      System.out.println(latitude+" "+longitude); 
      String url = "http://maps.google.com/maps?daddr="+ latitude + ","+longitude; 
      Intent geoIntent = new Intent(
        android.content.Intent.ACTION_VIEW,Uri.parse(url)); 
      startActivity(geoIntent); 
      System.out.println("url>>"+url); 

     } 

    } 

문제는 모든 주소에 대해 동일한 위도 및 경도 값을 얻는 것입니다.

몇 가지 해결책을 제공해주십시오.

답변

0

문제는 하나의 인스턴스 만 가져야하므로 주어진 마지막 값이됩니다. 당신이해야 할 일은 선언 된 주소 데이터를리스트 뷰 ArraysAdapter 클래스에 넣고 필요할 때 매개 변수로 전송하는 것입니다

+0

가능한 경우 몇 가지 예제 코드로 설명해주십시오. – user3684771

관련 문제