9 Ekim 2014 Perşembe

Windows Phone 7-8 | GPS Kullanımı

Merhaba, Bu yazımda Windows Phone uygulama geliştirirken GPS’den nasıl enlem – boylam bilgisi alacağımızı anlatacağım.
Windows Phone cihazlarda uygulama yazmanın avantajlarından biri çok hızlı bir şekilde yeni proje oluşturabilmeniz, ve projenize özellik katabilmeniz.
Bu makalede GPS’i nasıl projemize ekleyebileceğimiz yazılı. Projenizin isterseniz xaml sayfasının cs’sine isterseniz harici oluşturduğunuz cs’e entegre edebilirsiniz.
Ben locationcs diye bir class oluşturdum ve onun içinde öğreniyorum. böylece ihtiyacım olunca class’ı çağırıp location’umu alabiliyorum.
Lokasyon değerlerimi string olarak enlem ve boylam adı alınta 2 global değişkene atıyorum. dilerseniz get metodu ile bu değişkenleri alabilirsiniz.



using System.Device.Location; //ekstra gerekli olan bu!
namespace ProjeClasslar.classes
{
public class locationcs
{
public locationcs() {
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.MovementThreshold = 20;
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
watcher.Start();
}
GeoCoordinateWatcher watcher;
string accuracyText = “”;
string enlem = “”;
string boylam = “”;
private void StartLocationService(GeoPositionAccuracy accuracy)
{
watcher = new GeoCoordinateWatcher(accuracy);
watcher.MovementThreshold = 20;
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
watcher.Start();
}
void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(() => MyStatusChanged(e));
}
void MyStatusChanged(GeoPositionStatusChangedEventArgs e)
{
}
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
Deployment.Current.Dispatcher.BeginInvoke(() => MyPositionChanged(e));
}
void MyPositionChanged(GeoPositionChangedEventArgs<GeoCoordinate> e)
{
enlem = e.Position.Location.Latitude.ToString(“0.000″);
boylam = e.Position.Location.Longitude.ToString(“0.000″);
//bu noktada locationunuz belirlenmiş ve global değişkenlerden enlem ve boylama atılmış olmakta.
} } }
Tip1: Örnekte getlocation dediğinizde location class’ı oluşturduğu andaki locationu size verecektir.
Tip2: System.Device.Location referansını eklemeyi unutmayın;  Bende bu referans şurada: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone71\System.Device.dll
Kaynakça

Hiç yorum yok:

Yorum Gönder