Xamarin +vs2015 Android 開發GPS loaction 返回 null 小結,xamarinvs2015

來源:互聯網
上載者:User

Xamarin +vs2015 Android 開發GPS loaction 返回 null 小結,xamarinvs2015

 最近公司要開發android 所以研究了一下Xamarin  to android 中個GPS

廢話不多說,說重點。

想擷取手機上的gps資訊必不可少的就是要使用

LocationManager

Location 

有了這兩個類還不行要要給其許可權  ACCESS_FINE_LOCATION(如果要問這個許可權在哪裡,項目-屬性-Android Manifest)

我一開始把所有的代碼都寫在一個事件裡面,可以擷取到資訊,但是封裝了後就不行了。在baidu和google找了好長時間都說使用

DDMS  或者Telnet 來發送位置資訊,但是我都試了就是location返回null 

後來我還是查了API發現必須要在開始的時候聲明 LocationManager 和RequestLocationUpdates的資訊 

代碼如下

 LocationManager mLocationManager;

mLocationManager = GetSystemService(Context.LocationService) as LocationManager;

string Provider = LocationManager.GpsProvider;

if (mLocationManager.IsProviderEnabled(Provider))
{
mLocationManager.RequestLocationUpdates(Provider, 2000, 1, this);
}

否則模擬器上的gps表徵圖不會顯示,使用這句之後再點擊位置發送,就會看大模擬器上回出現gps的表徵圖

寫到這裡如果還不明白,可以郵件問我396116416@qq.com 或者我把源碼發給你。

如果我寫有不對的地方還請看到的大神多多指教,寫在這裡就是希望有遇到同樣的問題可以少走一些彎路

大家 一起進步。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.