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" />

     

  • 相关阅读:
    Kettle Spoon 数据源连接中报ORA12505, TNS:listener does not currently know of SID given in connect descriptor的错误
    oracle创建用户和删除用户sql
    Kettle Spoon表输入使用变量
    Kettle Spoon 资源库连接后新建转换打不开,报Invalid byte 1 of 1byte UTF8 sequence异常
    oracle 误删除表/表中数据,恢复方法
    让ie兼容css3新属性backroundsize
    网页设计中为啥少用奇数字体?
    浏览器差异总结,可以用此判断浏览器版本(转)
    ie浏览器f12下调“浏览器模式”和“文档模式”的区别
    jquery的淡入淡出和隐藏,展示函数在ie中应用的bug
  • 原文地址:https://www.cnblogs.com/renqingping/p/GoogleMap.html
Copyright © 2011-2022 走看看