2016-09-21 2 views
0

안녕하세요 전 gps 위치를 취해야하고 위도와 경도를 forcast.io에 대한 URL에 결합 해야하는 xamarin 양식의 응용 프로그램에서 일하고 있습니다. Geolocator 플러그인을 사용하고 있습니다. 제임스 Montemagno 및 추가 정보를 다음에하지만 난 여전히 이러한 오류를 받고 있어요 :제임스 Montemagno에 의해 Geolocator의 xamarin 플러그인과 문제가

'MSI'

심각도 코드 설명 프로젝트 파일 라인 할당되지 않은 지역 변수의

심각도 코드 설명 프로젝트 파일 라인 억제 상태 오류 CS0165 사용 억제 상태 오류 CS0266 암시 적으로 형식을 변환 할 수 없습니다 'Plugin.Geolocator.Abstractions.IGeolocator'to 'Plugin.Geolocator.CrossGeolocator'. 명시 적 변환은 가 (당신이 캐스트를 누락?) 존재

심각도 코드 설명 프로젝트 파일 라인 억제 상태 CS1061 'CrossGeolocator' 에 대한 정의를 포함하지 않는 'IsGeolocationEnabled'없이 확장 방법은 '을 IsGeolocationEnabled' 오류가 을 수용 유형 'CrossGeolocator'의 첫 번째 인수는 (당신은 using 지시문 또는 어셈블리 참조가?) 볼 수 있습니다

이 이

심각도 코드 설명 프로젝트 파일 라인 억제 상태가 오류 CS1061 'CrossGeolocator은' 에 대한 정의를 포함하지 않는 'GetPositionAsync'및 유형 'CrossGeolocator'의 첫 번째 인수를 받아들이는 더 확장 메서드 'GetPositionAsync' 는 (당신은 using 지시문 또는 어셈블리 참조가?) 찾을 수 없습니다

심각도 코드 설명 프로젝트 파일 라인 억제 상태 오류 CS1061 'CrossGeolocator을 볼 수 있습니다 DesiredAccuracy '없이 확장 메서드'CrossGeolocator '형식의 첫 번째 인수를 을 받아'DesiredAccuracy ' 에 대한 정의를 포함하지 않는'(using 지시문 또는 어셈블리 참조가 당신에게 이다?)

그리고 나서 여기에 그는 레이더 코드 :

using Xamarin.Forms; 
using System; 
using System.Diagnostics; 
using Plugin.Geolocator; 

namespace AppName.Radar 
{ 
    public interface MyLocationTracker 
    { 
     void ObtainMyLocation(); 
     event EventHandler<MyLocationEventArgs> locationObtained;  
    } 

    public interface MyLocationEventArgs 
    { 
     double lat { get; set; } 
     double lng { get; set; } 
    } 

    public partial class RadarHome : ContentPage 
    {  
     private readonly CrossGeolocator _locator; 
     private double BetaLat; 
     private double BetaLog; 

     public RadarHome() 
     { 
      MyLocationTracker msi; 

      _locator = CrossGeolocator.Current; 

      if (_locator.IsGeolocationEnabled == false) 
      { 
       if (Device.OS == TargetPlatform.Android) 
       {      

        msi.locationObtained += (object Esender, MyLocationEventArgs ew) => 
        { 
         Debug.WriteLine(ew.lat); 
        }; 
        msi.ObtainMyLocation(); 
       } 

       else if (Device.OS == TargetPlatform.iOS) 
       { 
        msi = DependencyService.Get<MyLocationTracker>(); 
        msi.locationObtained += (object Jsender, MyLocationEventArgs je) => 
        { 
         Debug.WriteLine(je.lat); 
        }; 
        msi.ObtainMyLocation(); 
       } 
      } 

      _locator.DesiredAccuracy = 50; 

      GetPositionAsynchronously(); 

      string str = string.Format(
       "https://forecast.io/?mobile=1#/f/Lat:{0} , Long: {1}", BetaLat, BetaLog); 

      var client = new System.Net.Http.HttpClient(); 

      client.BaseAddress = new Uri(str); 
     } 

     private async void GetPositionAsynchronously() 
     { 
      //will run asynchronously in a diff thread 
      var position = await _locator.GetPositionAsync(timeoutMilliseconds: 100000); 

      BetaLat = position.Latitude; //will work 
      BetaLog = position.Longitude; // will work  
     }  
    } 
} 

나는 (Froms, 아이폰 OS, 안드로이드) 내가 VS2015 업데이트 3을 사용하고 아직도 형태 xamrarin 배우고 그래서 나는 그런 질문에 대한 미안 해요 3 개 플랫폼에 설치된 최신 Geolocator의 nuget 패키지가 멍청한 놈.

미리 감사드립니다.

답변

0
if (Device.OS == TargetPlatform.Android) 
{  
    //You missed to resolve plugin there 
    msi = DependencyService.Get<MyLocationTracker>(); 

    msi.locationObtained += (object Esender, MyLocationEventArgs ew) => 
    { 
     Debug.WriteLine(ew.lat); 
    }; 
    msi.ObtainMyLocation(); 
} 
+0

그 역시 효과가있었습니다. 그 덕분에 대단히 고맙습니다 – Phoneswapshop

0

귀하의 _locator 정의 그래서이

private readonly IGeolocator _locator;

+0

! 대단히 감사합니다! – Phoneswapshop

0

모두 @William 옥수수 속대 데커 같이해야하고, @Greensy 답변이 정확

_locator 정의 하였다는 할 필요가 : private readonly IGeolocator _locator;

그리고 msi pl 문제를 해결하지 못했습니다. ugin을 heres 그 코드 :

if (Device.OS == TargetPlatform.Android) 
{ 
    //You missed to resolve plugin there 
    msi = DependencyService.Get<MyLocationTracker>(); 

    msi.locationObtained += (object Esender, MyLocationEventArgs ew) => 
    { 
     Debug.WriteLine(ew.lat); 
    }; 
    msi.ObtainMyLocation(); 
} 

내가 윌리엄 옥수수 속대 데커를 모두 표시 할 수 없습니다 때문에이 일을 해요, 그리고 Greensy이 같은 올바른 가득 신용 응답 유일한 이유는 둘 다에 간다!

다시 한 번 감사드립니다.

0

James Montemagno는 제 생각에는 Xamarin Forms 핵심 라이브러리 외부에서 Xamarin Forms에 가장 중요한 구성 요소를 작성했습니다. 불행히도, 어떤 시점에서 개별 구성 요소를 웹 전체에서 별도의 repos (라이브러리)로 분할하는 결정이 내려졌습니다. 샘플 작업을 위해 갈 수있는 장소가 없습니다.

우리는 그것을 정리, 자신의 코드의 일부를 촬영하고 플랫폼을 하나의 .NET 표준 라이브러리에 모두 넣어 특정 구현을 여기에 아이폰 OS, 안드로이드, 그리고 UWP를 위해 한 : https://github.com/MelbourneDeveloper/Adapt.Presentation.git

샘플 모두 실행하고, 문제가있는 경우 로그하여주십시오. 시간이 있으면 문제를 해결하려고 노력할 것입니다. GeoLocator 샘플은 확실히 작동합니다.

관련 문제