2017-11-01 2 views
0

주소를 얻으려고합니다. 지금까지 좌표를 가져 오는 데있어 모두설명 문구에 대한 MKPlacemark 주소를 얻는 방법 C# xamarin

CLLocation loc = new CLLocation(anno.Coordinate.Latitude, anno.Coordinate.Longitude); 

그러나 역 지오 코드 및 위치 표시를 사용해 보았습니다. 그들 중 누구도 작동하지 않습니다. 다음 예는 완료되지 않았으며 올바른 형식이 아닙니다. 나는 단지 신속한 것에서 복사하고있다.

async void ReverseGeocodeToConsoleAsync(CLLocation location) 
       { 
        var geoCoder = new CLGeocoder(); 
        var placemarks = await 
        geoCoder.ReverseGeocodeLocationAsync(location); 
        var placemark = placemarks[0] as CLPlacemark; 
        var addressString = ""; 
        //String to hold address 
         var locatedAtcountry = placemark.country; 
         var locatedAtcity = placemark.locality; 
         var locatedAtisocountry = placemark.ISOcountryCode; 
       if (placemark.ISOcountryCode == "TW") /*Address Format in Chinese*/ 
       { 
        if (placemark.country != null) 
        { 
         addressString = placemark.country! 
        } 
       } 

답변

0

코드가 성공한 것 같습니다. 다음은 위치에서 주소를 얻을 수있는 샘플입니다.

 public void GetAddress(CLLocation loc) 
     { 
      CLGeocoder ceo = new CLGeocoder(); 

      ceo.ReverseGeocodeLocation(loc, (placemarks, error) => 
      { 
       CLPlacemark placemark = placemarks[0]; 
       if (placemark != null) 
       { 
        Console.WriteLine(placemark.IsoCountryCode); 
        Console.WriteLine(placemark.Country); 
       } 
      }); 
     } 
+0

정말 고마워요! 이 모든 것이 맵 클래스 렌더러로 시도한 후에. 나는 페이지 렌더러로 더 나아 가기로 결정했다. 이벤트를 설정하는 방법을 모르기 때문에 UiSearchBar가 작동하지 않습니다. 검색 막대를 사용하여 이와 비슷한 작업을하고 싶습니다. – Pxaml

+0

비동기 void Handle_SearchButtonPressed (개체 보낸 사람, System.EventArgs e) { if (! string.IsNullOrWhiteSpace (SearchBar.Text)) { var address = SearchBar.Text; var approximateLocations = Geocoder.GetPositionsForAddressAsync (address); // 완료 없음 – Pxaml

+0

다음과 같이 트리거 할 수 있습니다 :'searchbar.SearchButtonPressed + = (sender, e) => {/ * 검색 버튼을 클릭 할 때 수행 할 작업 * /}; –

관련 문제