以下のリンクに基づくこのコード:
http://docs.xamarin.com/guides/android/platform_features/maps_and_location/part_3_-_location_services
Lat/Lon (Gps/Wifi) を取得できませんでした
コードは以下のとおりです。
追加しました: <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <:uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Android.Locations
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
//-- add these
using Android.Locations;
using System.Collections.Generic;
using System.Threading;
using System.Text;
using System.Linq;
using System.Xml;
namespace GPSWifi
{
[Activity (Label = "GPSWifi", MainLauncher = true)]
public class Activity1 : Activity
{
int count = 1;
private LocationManager _locMgr;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
InitializeLocationManager();
}
private void InitializeLocationManager()
{
_locMgr = (LocationManager) GetSystemService(LocationService);
var locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.NoRequirement;
locationCriteria.PowerRequirement = Power.NoRequirement;
string locationProvider = _locMgr.GetBestProvider(locationCriteria, true);
_locMgr.RequestLocationUpdates (locationProvider, 2000, 1, this);
}
protected override void OnResume ()
{
base.OnResume ();
_locMgr.RequestLocationUpdates (LocationManager.GpsProvider, 2000, 1, this);
}
protected override void OnPause ()
{
base.OnPause ();
_locMgr.RemoveUpdates (this);
}
public void OnProviderDisabled(string provider) {}
public void OnProviderEnabled(string provider) {}
public void OnLocationChanged (Location location)
{
var locationText = FindViewById<TextView>(Resource.Id.locationTextView);
locationText.Text = String.Format ("Latitude = {0}, Longitude = {1}",
location.Latitude, location.Longitude);
}
}
}
あなたの助けに感謝します。
- エラーメッセージ :
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2,2): エラー MSB4018: "Aapt" タスクが予期せず失敗しました。
System.InvalidOperationException: シーケンスに要素が含まれていません
System.Linq.Enumerable.First[TSource](IEnumerable`1 ソース) で
Xamarin.Android.Tasks.BuildToolsUtils.GetBuildToolsPath (文字列 androidSdkDirectory) で
Xamarin.Android.Tasks.Aapt.GenerateFullPathToTool() で
Microsoft.Build.Utilities.ToolTask.ComputePathToTool() で
Microsoft.Build.Utilities.ToolTask.Execute() で
Xamarin.Android.Tasks.Aapt.Execute() で
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() で
Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() (MSB4018) (GPSWifi) で