android 获取当前位置坐标 经度 纬度

android调用GPS获取当前位置                   并且用EditText显示出来


        如果有写的不好的地方        请大神指点一下     

代码如下:


package com.example.gps;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;



public class MainActivity extends Activity
{
    private EditText textView;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = (EditText) findViewById(R.id.editText1);
        new Thread(new ThreadShow()).start();启动线程
     
    }
    Handler handler=new Handler()
    {
        public void handleMessage(Message message)
        {
            if (message.what==1)
            {
                LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                  // 返回所有已知的位置提供者的名称列表,包括未获准访问或调用活动目前已停用的。
                 
                if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
                {
                    Location location=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                    if (location!=null)
                    {
                        //获取纬度信息
                        double latitude = location.getLatitude();
   

你可能感兴趣的:(Android开发)