{"id":624,"date":"2017-02-21T22:32:58","date_gmt":"2017-02-21T19:32:58","guid":{"rendered":"http:\/\/delimuhendis.org\/?p=624"},"modified":"2022-12-20T21:34:17","modified_gmt":"2022-12-20T21:34:17","slug":"android-ile-konum-servisleri-2","status":"publish","type":"post","link":"https:\/\/www.delimuhendis.org\/?p=624","title":{"rendered":"Android ile Konum Servisleri"},"content":{"rendered":"\n<p>Merhaba arkada\u015flar,<\/p>\n\n\n\n<p>Bug\u00fcn sizlerle beraber Android telefonunuzdaki GPS servislerini kullanarak konum bilgilerine eri\u015fme konusunu irdeleyece\u011fiz. &nbsp;\u00d6ncelikle bu konuya ge\u00e7meden \u00f6nce co\u011frafi koordinatlardan bahsetmek isterim.<br>D\u00fcnyam\u0131z\u0131n kendine has bir \u015fekli vard\u0131r ki bu \u015fekle&nbsp;Geoit denir.&nbsp;D\u00fcnyam\u0131z\u0131n \u00fczerinden ge\u00e7en yatay ve dikey do\u011frular vard\u0131r. Biz bu do\u011frulara s\u0131ras\u0131yla enlem(Latitude) ve boylam(Longitude) deriz. Bu do\u011frulara ait de\u011ferler ise bizim konumumuzu belirler.<\/p>\n\n\n\n<p>\u00dclkemiz,&nbsp;Kuzey Yar\u0131m K\u00fcre\u2019de, 36-42 derece kuzey enlemleriyle 26-45 derece do\u011fu boylamlar\u0131nda aras\u0131nda yer al\u0131r.<\/p>\n\n\n\n<p>Gelelim i\u015fin Android k\u0131sm\u0131na. Android i\u015fletim sistemi, y\u00fckl\u00fc oldu\u011fu cihazlara GPS kullan\u0131m\u0131 ve bu bilgilerin kullan\u0131c\u0131 taraf\u0131ndan izin verilmi\u015f uygulamalarla payla\u015f\u0131m\u0131 konusunda imkan sa\u011flar.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/delimuhendis.org\/wp-content\/uploads\/2017\/02\/Ekran-Resmi-2017-02-21-23.22.31.png\"><img decoding=\"async\" src=\"http:\/\/delimuhendis.org\/wp-content\/uploads\/2017\/02\/Ekran-Resmi-2017-02-21-23.22.31-1024x640.png\" alt=\"\" class=\"wp-image-625\"\/><\/a><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">1)Gerekli \u0130zinler<\/h3>\n\n\n\n<p><strong>AndroidManifest.xml<\/strong> dosyan\u0131z\u0131 a\u00e7\u0131n ve a\u015fa\u011f\u0131daki izinleri ekleyin.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"\/&gt;\n&lt;uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"\/&gt;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2)Layout Tasar\u0131m\u0131<\/h3>\n\n\n\n<p>\u015eimdi ise uygulamam\u0131z\u0131n aray\u00fcz tasar\u0131m\u0131n\u0131 yapaca\u011f\u0131z. Ve bize hayati derecede laz\u0131m olan \u015fey 2 adet textview. \u00c7\u00fcnk\u00fc biz bu textviewlere yazd\u0131raca\u011f\u0131z ald\u0131\u011f\u0131m\u0131z enlem ve boylam de\u011ferlerini. A\u015fa\u011f\u0131daki kodlar&nbsp;kodlar\u0131 layout dosyan\u0131za eklerseniz, bizim i\u00e7in yeterli olur.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;TextView\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    android:id=\"@+id\/txtEnlem\"\n    android:textAlignment=\"center\"\n    android:textSize=\"21sp\"\n    android:textColor=\"#ffffff\"\/&gt;\n&lt;TextView\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    android:id=\"@+id\/txtBoylam\"\n    android:textAlignment=\"center\"\n    android:textSize=\"21sp\"\n    android:textColor=\"#ffffff\"\/&gt;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3)Kodlama<\/h3>\n\n\n\n<p>Activity s\u0131n\u0131f\u0131n\u0131z\u0131 a\u00e7\u0131n ve <strong>LocationListener<\/strong> s\u0131n\u0131f\u0131n\u0131 implements edin. Hata verecektir ve sizden implemente edilen aray\u00fcze ait methodlar\u0131 eklemenizi isteyecetir. Implement methods diyerek bu hatay\u0131 \u00e7\u00f6zebilirsiniz.<br>Son durumda \u015fu \u015fekilde.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public class MainActivity extends Activity implements LocationListener<\/pre>\n\n\n\n<p>sonras\u0131nda s\u0131n\u0131f\u0131n hemen i\u00e7inde en \u00fcst k\u0131s\u0131mda her yerden eri\u015febilmek i\u00e7in bir global de\u011fi\u015fken tan\u0131ml\u0131yoruz.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public LocationManager locationManager;\nTextView txtEnlem,txtBoylam;<\/pre>\n\n\n\n<p>Sonra ise <strong>onCreate<\/strong> methodunun i\u00e7ine geliyoruz ve uygulama a\u00e7\u0131l\u0131r a\u00e7\u0131lmaz <strong>locationManager<\/strong> nesnemizin bir \u00f6rne\u011fini&nbsp;yarat\u0131yoruz. Ayr\u0131ca enlem ve boylam de\u011ferlerini yazd\u0131raca\u011f\u0131m\u0131z TextViewlerimizin de \u00f6rneklerini&nbsp;yarat\u0131yoruz.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);\ntxtEnlem=(TextView)findViewById(R.id.txtEnlem);\ntxtBoylam=(TextView)findViewById(R.id.txtBoylam);<\/pre>\n\n\n\n<p>Ard\u0131ndan da <strong>AndroidManifest<\/strong> dosyas\u0131nda ekledi\u011fimiz izinlerin bir de RunTime s\u0131ras\u0131nda istenmesini sa\u011flamak amac\u0131yla a\u015fa\u011f\u0131daki kodu ekliyoruz.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);<\/pre>\n\n\n\n<p>Bir sonraki ad\u0131mda ise <strong>LocationManager<\/strong> nesnemizin g\u00fcncel konumlardan haberdar olabilmesi i\u00e7in a\u015fa\u011f\u0131daki kodu ekliyoruz. 3000 de\u011ferinin girildi\u011fi parametre saniyeyi ifade eder ve 3 saniyede bir g\u00fcncelleme al\u0131nacak anlam\u0131na gelir.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">try\n{\n    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 10, this);\n}\ncatch (SecurityException ex)\n{\n    Toast.makeText(getApplicationContext(),ex.getMessage().toString(),Toast.LENGTH_LONG).show();\n}<\/pre>\n\n\n\n<p>art\u0131k <strong>onCreate<\/strong> methoduyla i\u015fimiz tamamlanm\u0131\u015f oluyor ve b\u00fct\u00fcn ayarlamalar\u0131 da yapm\u0131\u015f oluyoruz. \u015eimdi herhangi bir konum de\u011fi\u015fikli\u011fi oldu\u011funda bir \u015fey olmas\u0131n\u0131 sa\u011flamak i\u00e7in <strong>LocationListener<\/strong> aray\u00fcz\u00fcn\u00fc implemente etti\u011fimizde eklenen 4 methoddan 1&#8217;i olan <strong>onLocationChanged<\/strong> methodunun i\u00e7ini doldurmaya geldi s\u0131ra. A\u015fa\u011f\u0131daki kod ile her konum de\u011fi\u015fikli\u011fi oldu\u011funda yeni konumun enlem ve boylam de\u011ferlerini al\u0131p&nbsp;ekrana yazd\u0131raca\u011f\u0131z.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">txtEnlem.setText(\"Enlem:\"+location.getLatitude());\ntxtBoylam.setText(\"Boylam:\"+location.getLongitude());<\/pre>\n\n\n\n<p>Evet Arkdada\u015flar bug\u00fcnde Android ve Konum servisleriyle ilgili konumuzu i\u015fledik. Umar\u0131m faydal\u0131 bir yaz\u0131 olmu\u015ftur.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Merhaba arkada\u015flar, Bug\u00fcn sizlerle beraber Android telefonunuzdaki GPS servislerini kullanarak konum bilgilerine eri\u015fme konusunu irdeleyece\u011fiz. &nbsp;\u00d6ncelikle bu konuya ge\u00e7meden \u00f6nce&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1409,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[40,95,194,251,343,507],"class_list":["post-624","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programlama","tag-android","tag-boylam","tag-enlem","tag-gps","tag-konum","tag-servisleri"],"_links":{"self":[{"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=\/wp\/v2\/posts\/624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=624"}],"version-history":[{"count":2,"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=\/wp\/v2\/posts\/624\/revisions"}],"predecessor-version":[{"id":1413,"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=\/wp\/v2\/posts\/624\/revisions\/1413"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=\/wp\/v2\/media\/1409"}],"wp:attachment":[{"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.delimuhendis.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}