Android学习十一:高德地图使用
写这篇文章主要有三个目的:
1.使用高德地图api定位
2.获取天气数据
3.编程练手
文件结构

清单文件信息说明:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.tonny"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="****" /> <activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WeatherActivity"
android:label="@string/title_activity_weather" >
</activity>
</application> </manifest>
定位代码:
package org.tonny; import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.amap.api.location.LocationProviderProxy; import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.View; public class MainActivity extends Activity implements AMapLocationListener
{
LocationManagerProxy mLocationManagerProxy; @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mLocationManagerProxy = LocationManagerProxy.getInstance(MainActivity.this); /**
* 第一个参数,使用定位的类型,混合模型,如网络,gps等 第二个参数,定位周期 第三个参数,移动多少距离的时候生效(只有GPS模式下有效)
*/
mLocationManagerProxy.requestLocationData(LocationProviderProxy.AMapNetwork, 2 * 1000, 15, MainActivity.this);
} public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, WeatherActivity.class);
startActivity(intent);
} @Override
public void onLocationChanged(Location location)
{
// TODO Auto-generated method stub } @Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
// TODO Auto-generated method stub } @Override
protected void onDestroy()
{
super.onDestroy();
mLocationManagerProxy.destroy();
} @Override
public void onProviderEnabled(String provider)
{
// TODO Auto-generated method stub } @Override
public void onProviderDisabled(String provider)
{
// TODO Auto-generated method stub } @Override
public void onLocationChanged(AMapLocation location)
{
if (location != null && location.getAMapException().getErrorCode() == 0)
{
Log.e("Hello", location.toString());
}
} }
相应的布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查看天气"
android:onClick="onClick"/> </RelativeLayout>
天气代码:
package org.tonny; import com.amap.api.location.AMapLocalWeatherForecast;
import com.amap.api.location.AMapLocalWeatherListener;
import com.amap.api.location.AMapLocalWeatherLive;
import com.amap.api.location.LocationManagerProxy; import android.app.Activity;
import android.os.Bundle;
import android.util.Log; public class WeatherActivity extends Activity implements AMapLocalWeatherListener
{ private LocationManagerProxy mLocationManagerProxy; @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weather); mLocationManagerProxy = LocationManagerProxy.getInstance(WeatherActivity.this);
mLocationManagerProxy.requestWeatherUpdates(LocationManagerProxy.WEATHER_TYPE_LIVE, WeatherActivity.this);
} @Override
protected void onDestroy()
{ } @Override
public void onWeatherForecaseSearched(AMapLocalWeatherForecast forecast)
{ } /*
* (non-Javadoc)
*
* @see
* com.amap.api.location.AMapLocalWeatherListener#onWeatherLiveSearched(
* com.amap.api.location.AMapLocalWeatherLive)
*/
@Override
public void onWeatherLiveSearched(AMapLocalWeatherLive live)
{
Log.e("Weather", live.getCityCode());
Log.e("Weather", live.getCity());
Log.e("Weather", live.getTemperature()); Log.e("Weather", live.getWindDir());
}
}
相应的布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查看天气" /> </RelativeLayout>
Android学习十一:高德地图使用的更多相关文章
- Android项目外接高德地图代码混淆注意事项
如今好多项目中都加入了第三方jar包,可是最大的问题就是打包的时候代码混淆报错,下面是高德地图混淆报错解决方式: 在proguard-project.txt中加入例如以下代码: -libraryjar ...
- Android Studio之高德地图实现定位和3D地图显示
在应用开发中,地图开发是经常需要使用的“组件”,国内比较出名的是就是百度地图和高德地图. 此博客讲的是高德地图实现定位和3D地图显示,并标注相应位置,话不多说,先看看效果,在上代码. 效果如图: 首先 ...
- 关于Android studio调用高德地图的简单流程和要点
一,账号与Key的申请 注册成为高德开发者需要分三步: 第一步,注册高德开发者:第二步,去控制台创建应用:第三步,获取Key. 前2步都比较简单,这里说下第三步. 获取Key 1.进入控制台,创建一个 ...
- android开发对应高德地图定位服务进度一
进行android的高德地图开发首先需要进入高德地图的控制台进行注册登录.之后创建新的应用并且绑定软件得到相应的key. 这里面需要找到自己软件对应的多个SHA1.这里有发布版和调试版,以及对应的软件 ...
- Android开发实现高德地图定位
1.获取Key 参考官方文档:http://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key 对于签名文件的获取建议 ...
- android学习十一 高级调试分析功能
1.debug 功能列表 2.ddms功能( 内存检查,线程检查,视图层次分析) 3.跟踪代码 TraceView 4.命令行工具 adb 5.策略检查StrictMode
- 【高德地图Android SDK】视频教学
前两天参加了高德在北航举办的公开课,感觉非常不错.完成老师布置的作业之后,还顺利地拿到了高德开发者认证证书!! 现在来跟大家分享一下,如何快速学习[高德地图Android SDK]的开发.一天包会!连 ...
- 十一、Android学习第十天——项目开始(转)
(转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 十一.Android学习第十天——项目开始 Android知识点的学习告一 ...
- android 高德地图出现【定位失败key鉴权失败】
如题:android 高德地图出现[定位失败key鉴权失败] 原因:使用的是debug模式下的SHA1,发布的版本正确获取SHA1的方式见: 方法二使用 keytool(jdk自带工具),按照如下步骤 ...
随机推荐
- GridView不能添加头布局,并且scrollView与GridView冲突导致一些页面无法融合
此贴为标记贴 方便下次使用 在项目需求中原本是用ScrollView来进行整个页面的滑动,ScrollView里面包含的有图片轮播,文字轮播,与2列GridView的item 问题 使用原生的Grid ...
- RecyclerView因版本问题无法加载
前几天在学习RecyclerView时候,一直失败,各种加载不上.下面是错误信息 D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL ...
- Android Studio 常用快捷键
继承Eclipse的快捷键 : File->Settings->Keymap->有一个Keymaps 下拉菜单,选择Eclipse. 这里讲主要常用的快捷键 : Ctrl ...
- Ubuntu系统下Xen虚拟机的基本安装方法(代码创建)
Ubuntu上Xen安装虚拟机方法一dd一个空的磁盘sudo dd if=/dev/zero of=/home/vm1.img bs=1G count=8 下载Xen VM通用配置文件 sudo wg ...
- CRYPTO-MD5
这是昨天WHUCTF比赛的一道题目,本属于crypto,其实和crypto没多大关系, 比赛时其实差不多有这种思路了,但不相信自己,就没这样做下去,回来之后,照做了,果然是这样 链接:http://p ...
- ThinkPHP_基础(1)目录结构
(说明:文中的颜色一一对应) 目录结构 www WEB部署目录(或者子目录) ├─index.php 入口文件 ├─README.md README文件 ├─composer.json Compose ...
- 如何开发H5项目 -- 入门篇
前言 H5即HTML5,H5开发具有低成本.高效率.跨平台.研发周期短,用户接触成本低等特性. 一.开发环境 在开发一个H5项目之前,需要先搞好环境.主要有node.npm.gulp.bower.下面 ...
- PHP与Golang如何通信?
PHP与Golang如何通信? 最近遇到的一个场景:php项目中需要使用一个第三方的功能(结巴分词),而github上面恰好有一个用Golang写好的类库.那么问题就来了,要如何实现不同语言之间的通信 ...
- Echarts 动态折线图
<script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script>< ...
- 音乐播放(AVAudioPlayer)