2013-10-02 2 views
0

Android 용 Xamarin에서 Google Map API를 사용하려고 시도하고 있으며 지금까지는 경험이 없었습니다. 나는 Xamarin을 처음 사용하고 있으며 Xamarin을 사용하려고 노력하고있다. 몇 가지 기본 컨트롤을 테스트하고 잘 작동하는 것 같습니다. 이제 Google Map Api를 사용하려고합니다. Xamarin 문서에 따라 AndroidManifest.xml에 Api 키를 삽입했습니다. 내 Main.axml에 다음 코드가 파일이 나는 그것이 예외Xamarin에서 Google Map 사용하기

Android.Views.InflateException: Loading 

에게 던져 위의 코드를 실행하면 다음

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.MapFragment" /> 
</LinearLayout> 

내 활동 클래스

[Activity (Label = "Testing", MainLauncher = true)] 
    public class MainActivity : Android.GoogleMaps.MapActivity 
    { 

     protected override bool IsRouteDisplayed { 
      get { 
       return false; 
      } 
     } 

     protected override void OnCreate (Bundle bundle) 
     { 
      base.OnCreate (bundle); 


      SetContentView (Resource.Layout.Main); 

      // Get our button from the layout resource, 
      // and attach an event to it 
      //Button button = FindViewById<Button> (Resource.Id.myButton); 

      //button.Click += delegate { 
      // button.Text = string.Format ("{0} clicks!", count++); 
      //}; 
     } 
    } 

이다 나는 돈 ' VS에서 일반적으로하는 것처럼 오류에 대한 세부 정보를 얻지 못합니다. 나는 무엇이 잘못되었는지 전혀 모른다. 화면에서 무엇인가를보고 그걸 가지고 노는 순간에 맹목적으로 문서를 읽는 중이다. 그러나 그것은 곧 추측 할 수 없다.

Google은이 테스트 프로젝트를 위해 Google API 버전 8을 타겟팅하고 있습니다.

여기에 무엇이 누락 되었습니까?

+0

OpenStreetMap 지원은 어떻습니까? Google지도에 엄격히 구속되지 않은 경우 OpenStreetMap을 사용하는 샘플을 게시 할 수 있습니다. – HuseyinUslu

+0

@HuseyinUslu 내 유일한 요구 사항은 내가 가장 가까운 주유소를 보여주고 사용자가 선택한 주유소에 대한 경로를 그려야한다는 것입니다. OpenStreetMap이 이러한 기능을 지원한다면 나는 당신의 도움에 기뻐할 것입니다. 고마워! –

+0

통합 단계와 API 키를 확인하십시오. http://appliedcodelog.blogspot.in/2015/04/build-google-map-v2-in-xamarin-android에 도움이 될 수 있습니다.htaccess Admin Home English Language Content – Suchith

답변

0

Google지도 V2를 사용하는 경우,이 페이지를 살펴 걸릴 : http://components.xamarin.com/view/googleplayservices/

그리고 당신은 API (8)을 대상으로하는 경우 Mono.Android.Support.v4의 assemly를 참조하는 것을 잊지하고,하지를 그에 따라 요소를 사용하십시오!

<FrameLayout 
     android:id="@+id/mapView" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:clickable="true" 
     android:longClickable="true" 
     android:layout_below="@+id/textLayout" 
     android:layout_above="@+id/footerLayout" /> 

그리고 내 클래스 : 내 레이아웃처럼 보이는 방법은 다음과

이다

public class GoogleMapActivity : Android.Support.V4.App.FragmentActivity 
{ 
     protected override void OnCreate(Bundle bundle) 
     { 
     var fragTx = SupportFragmentManager.BeginTransaction(); 
     var mapFragment = Android.Gms.Maps.SupportMapFragment.NewInstance(mapOptions); 
     fragTx.Add(Resource.Id.mapView, mapFragment, "mapView"); 
     fragTx.Commit(); 
     } 
} 
+0

감사합니다 루즈 벨트, 나는 당신의 코드를 시도했지만 뭔가를 놓친 것 같습니다. 저는 VS를 사용하고 있으며 이미 Mono.Android.Support.v4 어셈블리에 대한 참조를 추가했습니다. 그러나 내가 당신의 코드를 작성하려고 할 때,이 오류가 발생합니다. 오류 패키지이 com.google.android.maps은 (com.google.android.maps.ItemizedOverlay P0, com.google.android.maps.OverlayItem P1) \t 개인 기본 무효 n_onFocusChanged 존재하지 않는다; \t C : \ src \ mono \ com \ google \ android \ maps \ ItemizedOverlay_OnFocusChangeListenerImplementor.java –

+0

패키지를 추가 할 필요가 있지만 어디서 어떻게 패키지를 하나씩 추가해야 할 것 같습니까? –

+0

이 솔루션을 사용해 보셨습니까? http://forums.xamarin.com/discussion/1018/problem-with-google-maps – Roosevelt

0

이 정확하게 귀하의 질문에 있지만 대안에 대한 답변을하지 않습니다;

나는 안드로이드를 통해 xamarin을 사용하여 leaflet 및/또는 mapbox과 OpenStreetMaps를 사용 해왔다. 주유소 등을 걸러 낼 수 있는지 확실하지 않지만.

다음은 모바일지도를 렌더링하는 데 사용하는 코드입니다.

public class MainActivity : Activity//, ILocationListener 
{ 
    private WebView _webView; 
    private MonkeyWebViewClient _webViewClient; 
    private MonkeyWebChromeClient _webChromeClient; 

    ... 

    protected override void OnCreate (Bundle bundle) 
    { 
     Log.Verbose (LogAppTag, "Init webview.."); 
     _webView = FindViewById<WebView> (Resource.Id.webView1); 
     _webView.Settings.JavaScriptEnabled = true; 

     _webViewClient = new MonkeyWebViewClient (this); 
     _webChromeClient = new MonkeyWebChromeClient(); 
     _webViewClient.OnLoadComplete += WebLoadComplete; 

     _webView.SetWebViewClient(_webViewClient); 
     _webView.SetWebChromeClient(_webChromeClient);  

     _webView.LoadUrl("file:///android_asset/Content/Map/Map.html"); 

    ... 

    void WebLoadComplete (object sender, EventArgs e) 
    { 
     Log.Verbose(Logging.AppTag, "WebLoadComplete()"); 
     _webView.LoadUrl("javascript:SetLocation(" + _location.Latitude + "," + _location.Longitude + ");");  
    } 
    ... 
    class MonkeyWebChromeClient : WebChromeClient { 
     public override bool OnJsAlert(WebView view, string url, string message, JsResult result) 
     { 
      // the built-in alert is pretty ugly, you could do something different here if you wanted to 
      return base.OnJsAlert(view, url, message, result); 
     } 
    } 

    class MonkeyWebViewClient : WebViewClient 
    { 
     public bool LoadingFinished { get; private set; } 

     public delegate void LoadCompleteHandler(object sender, EventArgs e); 
     public event LoadCompleteHandler OnLoadComplete; 

     Activity context; 

     public MonkeyWebViewClient(Activity context) 
     { 
      this.context = context; 
     } 
     public override bool ShouldOverrideUrlLoading(WebView view, string url) 
     { 
      view.LoadUrl (url); 
      return true; 
     } 

     public override void OnPageStarted (WebView view, string url, Android.Graphics.Bitmap favicon) 
     { 
      this.LoadingFinished = false; 
      base.OnPageStarted (view, url, favicon); 
     } 

     public override void OnPageFinished (WebView view, string url) 
     { 
      this.LoadingFinished = true; 

      var handler = OnLoadComplete; 
      if (handler != null) handler(this, EventArgs.Empty); 

      base.OnPageFinished (view, url); 
     } 
    } 

여기에 webview에서로드하는 html 코드가 있습니다.

<html> 
<head> 
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 
<!-- mapbox --> 
<script src='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.js'></script> 
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.css' rel='stylesheet' />  
<!-- mapbox --> 
    </head> 
<style> 
    body { 
     padding: 0; 
     margin: 0; 
    } 
    html, body, #map { 
     height: 100%; 
    } 
</style> 
<div id="map"></div>   
<script src="JS/Map.js"></script>   
</html> 

그리고 C# 코드와 통신 할 수있는 JS 코드. 맵 박스 위에 새 맵을 만들고 raistlinthewiz.map-oukwofv3 부분을 변경하려고합니다.

// map code.    
function SetLocation(lat, lng) 
{ 
    var latlng = new L.LatLng(parseFloat(lat), parseFloat(lng)); 

    // mapbox 
    var map = L.mapbox.map('map', 'raistlinthewiz.map-oukwofv3').setView(latlng, 18);     

    L.mapbox.markerLayer({ // this feature is in the GeoJSON format: see geojson.org for the full specification 
     type: 'Feature', 
     geometry: { 
      type: 'Point', // coordinates here are in longitude, latitude order because x, y is the standard for GeoJSON and many formats 
      coordinates: [parseFloat(lng), parseFloat(lat)] 
     }, 
     properties: { // one can customize markers by adding simplestyle properties http://mapbox.com/developers/simplestyle/ 
      title: 'A Single Marker', 
      description: 'Just one of me',    
      'marker-size': 'large' 
     } 
    }).addTo(map); 
} 

바닐라 - 전단지를 사용하는 샘플도 제공 할 수 있습니다.