GPS Kullanım Tamamını indir

package com.example.ali.gpskullanm;

import android.Manifest;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedWriter;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    LocationListener ll;
    LocationManager lm;
    Context c;
    double enlem, boylam;
    TextView tenlem,tboylam;
    ConnectivityManager cm;
    NetworkInfo networkinfo;
    AlertDialog.Builder dialog;
    int saat=(1000*60*60);
    vt vt_sinfi;
    SQLiteDatabase db;
    Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        c = this;
        vt_sinfi=new vt(c);
        btn=(Button)findViewById(R.id.btn);
        btn.setOnClickListener(this);

        tenlem=(TextView)findViewById(R.id.enlem);
        tboylam=(TextView)findViewById(R.id.boylam);
        dialogcreate();

    }
    public void dialogcreate()
    {
        dialog=new AlertDialog.Builder(c);
        dialog.setTitle("Konum");
        dialog.setMessage("Konumu Açınız!!");
        dialog.setPositiveButton("Tamam", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        dialog.create().show();
    }
    public void init()
    {
        lm=null;
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        ll = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                enlem = location.getLatitude();
                boylam = location.getLongitude();
                tenlem.setText(enlem+"");
                tboylam.setText(boylam+"");
                cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
                networkinfo=(NetworkInfo) cm.getActiveNetworkInfo();
                if(networkinfo!=null&&networkinfo.isConnected())
                {
                    if(veri_kontrol())
                        sunucuya_ekle();
                    post(enlem+"",boylam+"");
                }
                else
                {
                    konum_ekle(enlem+"",boylam+"");
                    Toast.makeText(c, "Konum veritabnına kayıtedildi", Toast.LENGTH_LONG).show();
                }
                lm.removeUpdates(ll);

            }
            @Override
            public void onStatusChanged(String s, int i, Bundle bundle) {

            }
            @Override
            public void onProviderEnabled(String s) {
                Toast.makeText(c, "GPS Veri bilgileri Alınıyor...", Toast.LENGTH_LONG).show();
            }
            @Override
            public void onProviderDisabled(String s) {
                Toast.makeText(c, "GPS Bağlantı Bekleniyor...", Toast.LENGTH_LONG).show();
            }
        };
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(c,"Konum açınız!!!",Toast.LENGTH_LONG).show();
            return;
        }
        if(networkinfo!=null&&networkinfo.isConnected()) {//bağlandı ise tru döndürür
            lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,6000,0, ll);
        }
        else
        {
            lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 6000, 0, ll);
        }
    }
    public  void post(final String enlem, final String boylam)
    {

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    URL url = new URL("http://alikomesogutlu.org/yandexmap.php");
                    HttpURLConnection  conn = (HttpURLConnection) url.openConnection();
                    conn.setReadTimeout(10000);
                    conn.setConnectTimeout(15000);
                    conn.setRequestMethod("POST");
                    conn.setDoInput(true);
                    conn.setDoOutput(true);

                    Uri.Builder builder = new Uri.Builder()
                            .appendQueryParameter("enlem",enlem)
                            .appendQueryParameter("boylam", boylam);
                    String query = builder.build().getEncodedQuery();

                    OutputStream os = conn.getOutputStream();//bağlantının cıkısı
                    BufferedWriter writer = new BufferedWriter(
                            new OutputStreamWriter(os, "UTF-8"));
                    writer.write(query);
                    writer.flush();
                    writer.close();
                    os.close();
                    conn.connect();
                    Log.d("hata",conn.getResponseMessage());
                }
                catch (Exception ex)
                {

                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        Toast.makeText(c,"Konum sunucuya kayıt edildi.",Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }).start();
    }
    public void baglan()
    {
        try {
            db=vt_sinfi.getWritableDatabase();
        }
        catch (Exception ex)
        {
            Toast.makeText(c,ex.getMessage(),Toast.LENGTH_SHORT).show();
        }
    }
    public void konum_ekle(String enlem,String boylam)
    {
        try {
            baglan();
            ContentValues par=new ContentValues();
            par.put("enlem",enlem);
            par.put("boylam",boylam);
            db.insertOrThrow("konum",null,par);
            db.close();
        }
        catch (Exception ex)
        {
            Toast.makeText(c,ex.getMessage(),Toast.LENGTH_SHORT).show();
        }
    }
    public void sunucuya_ekle()
    {
        try {
            baglan();
            Cursor cursor=db.query("konum",new String[]{"enlem","boylam"},null,null,null,null,null);
            cursor.moveToPosition(-1);
            while (cursor.moveToNext())
                post(cursor.getString(0),cursor.getString(1));
            cursor.close();
            vt_sinfi.onUpgrade(db,0,0);
            db.close();
        }
        catch (Exception ex)
        {
            Toast.makeText(c,ex.getMessage(),Toast.LENGTH_SHORT).show();
        }
    }
    public boolean veri_kontrol()
    {
        try {
            baglan();
            Cursor cursor=db.rawQuery("select * from konum",null);
            if(cursor.getCount()>0)
            {   db.close();
                return true;
            }
            else {
                db.close();
                return false;
            }
        }
        catch (Exception ex)
        {
            Toast.makeText(c,ex.getMessage(),Toast.LENGTH_SHORT).show();
            return false;
        }
    }

    @Override
    public void onClick(View view) {
        init();
    }
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<?php
$enlem='36.584014';
$boylam='36.163995'; 
if(isset($_POST['konum']))
{
	$enlem_boylam=explode(",",$_POST['konum']);
	$enlem=$enlem_boylam[0];
	$boylam=$enlem_boylam[1];

}
if(isset($_POST['enlem'])&&isset($_POST['boylam']))
{
$dosya=fopen('konum.txt','a');
fwrite($dosya,$_POST['enlem'].",".$_POST['boylam']."-");
fclose($dosya);
}
else
{
	try{
$dosya=fopen('konum.txt','r');
$boyut=filesize('konum.txt');
$veri=fread($dosya,$boyut);
fclose($dosya);
$konum=explode("-",$veri);

	}
	catch(Exception $ex)
	{
		echo $ex->getMessage();
	}
?>
    <title>YMapsML examples. Map parameters</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	 <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20src%3D%22http%3A%2F%2Fapi-maps.yandex.ru%2F2.0%2F%3Fload%3Dpackage.full%26lang%3Dtr-TR%22%20type%3D%22text%2Fjavascript%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" />
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20type%3D%22text%2Fjavascript%22%3E%0D%0Aymaps.ready(init)%3B%0D%0Afunction%20init%20()%20%7B%0D%0A%20%20%20var%20myMap%20%3D%20new%20ymaps.Map('map'%2C%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20center%3A%20%5B%3C%3Fphp%20echo%20%24enlem%3B%3F%3E%2C%20%3C%3Fphp%20echo%20%24boylam%3B%3F%3E%5D%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20zoom%3A%2012%0D%0A%20%20%20%20%20%20%20%7D)%2C%0D%0A%20%20%20%20%20%20%20myPlacemark%20%3D%20new%20ymaps.Placemark(%5B%3C%3Fphp%20echo%20%24enlem%3B%3F%3E%2C%20%3C%3Fphp%20echo%20%24boylam%3B%3F%3E%5D%2C%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20content%3A%20'%C4%B0skenderun!'%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20balloonContent%3A%20'Buradas%C4%B1n%C4%B1z!!!!'%0D%0A%20%20%20%20%20%20%20%7D)%3B%0D%0A%20%20%20myMap.controls%0D%0A%20%20%20%20%20%20%20.add('searchControl'%2C%20%7B%20left%3A5%2C%20top%3A%205%20%7D)%0D%0A%20%20%20%20%20%20%20.add('smallZoomControl'%2C%20%7B%20left%3A%205%2C%20top%3A%20165%20%7D)%0D%0A%20%20%20%20%20%20%20.add('typeSelector')%0D%0A%20%20%20%20%20%20%20.add('mapTools'%2C%20%7B%20left%3A%205%2C%20top%3A%20460%20%7D)%0D%0A%20%20%20%20%20%20%20.add('trafficControl'%2C%20%7B%20left%3A%20270%2C%20top%3A%205%20%7D)%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20myMap.geoObjects.add(myPlacemark)%3B%0D%0A%7D%0D%0A%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" />
</head>
<body>
<table>
<tr><td>
<form method="post">
<select name="konum" id="konum" onchange='this.form.submit()' >
<option value="Seçiniz...">Seçiniz...</option> 
<?php
for($i=0;$i<count($konum)-1;$i++){
?>
<option value="<?php echo $konum[$i];?>"><?php echo $konum[$i];?></option> 
<?php }?>
</select>
</form>
</td><td>
<?php 
}
?>
    <div id="map" style="width:640px; height:400px;"></div>
</td>
</tr>
</table>
</body>
</html>