zoukankan      html  css  js  c++  java
  • Google地图开发

    配置Google API SDK

    如果要想进行Google Map或者说是定位服务的开发,那么肯定需要下载一个新的SDK的支持。

    1、点击Android SDK Manager,下载SDK。

    2、直接配置已经下载好的SDK到项目中。

    配置完Google API SDK之后,那么下面就需要建立一个适合于Google的SDK的虚拟机。

    LocationManager的使用

    1、主要逻辑部分

    /**
     * 
     * @author Harvey
     * 
     * 
     */
    public class MyGPSDemo extends Activity
    {
        private TextView msg = null; // 显示坐标信息
        private LocationManager locationManager = null; // 位置管理
    
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            super.setContentView(R.layout.main); // 默认布局管理器
    
            msg = (TextView) super.findViewById(R.id.msgTv); // 获得组件
            locationManager = (LocationManager) super.getSystemService(Context.LOCATION_SERVICE); // 取得位置服务
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, // GPS定位提供者
                    1000, // 时间间隔设置为1秒
                    1, // 位置间隔设置为1米
                    new MyLocationListener()); // 设置位置监听
        }
    
        private class MyLocationListener implements LocationListener
        {
    
            @Override
            public void onLocationChanged(Location location)
            {
                // 设备位置发生改变时触发
                msg.setText("用户位置发生改变,新的位置数据:
    " + "经度:" + location.getLongitude() + "
    " + "纬度:"
                        + location.getLatitude() + "
    " + "数据精确度:" + location.getAccuracy() + "
    "
                        + "时间:" + location.getTime() + "
    " + "速度:" + location.getSpeed() + "
    "
                        + "方位:" + location.getBearing()); // 设置文本信息
            }
    
            @Override
            public void onProviderDisabled(String provider)
            {
                // 当数据提供者关闭时触发
            }
    
            @Override
            public void onProviderEnabled(String provider)
            {
                // 当数据提供者启用时触发
            }
    
            @Override
            public void onStatusChanged(String provider, int status, Bundle extras)
            {
                // 当位置信息状态更新时触发
            }
        }
    }

    2、布局文件main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/msgTv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/get_msg" />
    
    </LinearLayout>

    3、需要在AndroidManifest.xml文件中添加权限

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

     

  • 相关阅读:
    Educational Codeforces Round 67 D. Subarray Sorting
    2019 Multi-University Training Contest 5
    Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code
    Educational Codeforces Round 69 D. Yet Another Subarray Problem
    2019牛客暑期多校训练第六场
    Educational Codeforces Round 68 E. Count The Rectangles
    2019牛客多校第五场题解
    2019 Multi-University Training Contest 3
    2019 Multi-University Training Contest 2
    [模板] 三维偏序
  • 原文地址:https://www.cnblogs.com/renqingping/p/GoogleMap.html
Copyright © 2011-2022 走看看