zoukankan      html  css  js  c++  java
  • 用户定位

    代码如下:

    AndroidManifest.xml:

    在</application>后面增加一行:

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    Activity_main.xml:

        <Button

           android:id="@+id/locationButtonId"

           android:layout_width="fill_parent"

           android:layout_height="wrap_content"

            android:text="绑定监听器"/>

    MainActivity.java:

    package leihu.location01;

    import android.location.Location;

    import android.location.LocationListener;

    import android.location.LocationManager;

    import android.os.Bundle;

    import android.app.Activity;

    import android.content.Context;

    import android.view.View;

    import android.view.View.OnClickListener;

    import android.widget.Button;

    public class MainActivity extends Activity {

        private Button button = null;

        protected void onCreate(Bundle savedInstanceState) {

           super.onCreate(savedInstanceState);

           setContentView(R.layout.activity_main);

           button = (Button)findViewById(R.id.locationButtonId);

           button.setOnClickListener(new ButtonListener());

        }

        private class ButtonListener implements OnClickListener{

           public void onClick(View v) {

               //得到LocationManager对象

               LocationManager locationManager = (LocationManager)MainActivity.this.getSystemService(Context.LOCATION_SERVICE);

               //1.定义当前所使用的Location Provider     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,newTestLocationListener());

           }

        }

        private class TestLocationListener implements LocationListener{

           public void onLocationChanged(Location location) {

               // TODO Auto-generated method stub

               System.out.println(location.getLongitude());

               System.out.println(location.getLatitude());

           }

           public void onProviderDisabled(String provider) {

               // TODO Auto-generated method stub

            }

           public void onProviderEnabled(String provider) {

               // TODO Auto-generated method stub

           }

           public void onStatusChanged(String provider, int status, Bundle extras) {

               // TODO Auto-generated method stub

           }

        }

    }

  • 相关阅读:
    沟通的5个步骤
    安家博客园,发表感想
    postman 简单教程-实现简单的接口测试
    Postman的基本使用
    面试题-如何测试一个APP
    Fiddler快捷方式导出jmeter脚本,傻瓜式
    Servlet学习(三)
    scala学习(一)
    白底抠图
    Servlet学习(二)
  • 原文地址:https://www.cnblogs.com/leihupqrst/p/3722193.html
Copyright © 2011-2022 走看看