2012-10-26 2 views
0

네이티브 Google지도에서 수행되는 것처럼 사용자 지정지도 응용 프로그램에서 검색 기능을 구현해야합니다 (작업 표시 줄이 검색 필드로 바뀌고 쿼리를 작성할 수 있습니다) . 이제 google geocoding api을 사용하는 방법과 데이터에서 위치를 검색하는 방법을 알고 있습니다. 그러나 나는 변덕스러운 액션 바를 구현하지 못했습니다.네이티브 Google지도와 같은 사용자 지정 응용 프로그램에지도 검색 기능 구현

enter image description here

을 그리고 검색 버튼을 누른 후 나는 표시 레이아웃 이런 종류의하고 싶은 :

내 애플처럼 보이는 도움을

enter image description here

감사합니다 잘하면 내 문제를 해결할 수 있습니다.

+1

이 문제는 구글지도 API V3에 대한 아닙니다. (태그 제거). – Marcelo

답변

2

다음은 검색 기능을위한 몇 가지 코드입니다. 이 코드는 저와 함께 작동합니다. 위치 이름을 입력하면지도에서 정확히 일치하는 장소로 리디렉션됩니다. 다음 코드는 먼저 LatLang에서 이름과 초로 검색하는 두 가지 방법을 제공합니다. 이름 og의 위치 LAtLang으로

public void searchPlace() 
{  

    AlertDialog.Builder alert = new AlertDialog.Builder(this); 

    alert.setTitle("Search Location"); 
    alert.setMessage("Enter Location Name: "); 

    // Set an EditText view to get user input 
    final EditText input = new EditText(this); 
    alert.setView(input); 

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 
     String value = input.getText().toString(); 
     // Do something with value! 
     Log.d("value", value); 

     Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());  
     try { 
      List<Address> addresses = geoCoder.getFromLocationName(
       value, 5); 
      String add = ""; 
      if (addresses.size() > 0) { 
       p = new GeoPoint(
         (int) (addresses.get(0).getLatitude() * 1E6), 
         (int) (addresses.get(0).getLongitude() * 1E6)); 
       mc.animateTo(p); // create mapController object like `MapController mc = mapView.getController();` 
       mapView.invalidate(); 
      }  
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 


     } 
    }); 

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
     // Canceled. 
     } 
    }); 

    alert.show(); 

} 
  • 으로

    1. .

      public void byLatLang() 
      {  
      
          LayoutInflater factory = LayoutInflater.from(this);    
          final View textEntryView = factory.inflate(R.layout.latlong, null); 
      
          AlertDialog.Builder alert = new AlertDialog.Builder(this); 
      
          alert.setTitle("Search Location"); 
          alert.setMessage("Enter Lattitude and Longitude: "); 
      
          alert.setView(textEntryView); 
          // Set an EditText view to get user input 
          AlertDialog latLongPrompt = alert.create(); 
      
          final EditText lat = (EditText) textEntryView.findViewById(R.id.lat); 
          final EditText longi = (EditText) textEntryView.findViewById(R.id.longi); 
      
          alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int whichButton) { 
      
           Toast.makeText(getBaseContext(), "clicked ok ", Toast.LENGTH_SHORT).show(); 
           Double value1 = Double.parseDouble(lat.getText().toString()); 
           Double value2 = Double.parseDouble(longi.getText().toString()); 
           // Do something with value! 
              //Log.d("value1", value1); 
            //Log.d("value2", value2); 
      
           p = new GeoPoint(
             (int) (value1 * 1E6), 
             (int) (value2 * 1E6)); 
      
            mc.animateTo(p); 
            mc.setZoom(17); 
            mapView.invalidate(); 
      
      
           } 
          }); 
      
          alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog, int whichButton) { 
           // Canceled. 
           } 
          }); 
      
          alert.show(); 
      
      } 
      
  • +0

    답변을 주셔서 감사 드리며 멋진 답변입니다. 그러나 주된 문제는 그것으로 해결되지 않습니다. 기본 Google지도와 마찬가지로 액션 바를 변경해야합니다. 나는 당신의 질문을 upvoted했지만 그것을 받아 들일 수 없습니다. – Csabi