写这篇文章主要有三个目的:

  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学习十一:高德地图使用的更多相关文章

  1. Android项目外接高德地图代码混淆注意事项

    如今好多项目中都加入了第三方jar包,可是最大的问题就是打包的时候代码混淆报错,下面是高德地图混淆报错解决方式: 在proguard-project.txt中加入例如以下代码: -libraryjar ...

  2. Android Studio之高德地图实现定位和3D地图显示

    在应用开发中,地图开发是经常需要使用的“组件”,国内比较出名的是就是百度地图和高德地图. 此博客讲的是高德地图实现定位和3D地图显示,并标注相应位置,话不多说,先看看效果,在上代码. 效果如图: 首先 ...

  3. 关于Android studio调用高德地图的简单流程和要点

    一,账号与Key的申请 注册成为高德开发者需要分三步: 第一步,注册高德开发者:第二步,去控制台创建应用:第三步,获取Key. 前2步都比较简单,这里说下第三步. 获取Key 1.进入控制台,创建一个 ...

  4. android开发对应高德地图定位服务进度一

    进行android的高德地图开发首先需要进入高德地图的控制台进行注册登录.之后创建新的应用并且绑定软件得到相应的key. 这里面需要找到自己软件对应的多个SHA1.这里有发布版和调试版,以及对应的软件 ...

  5. Android开发实现高德地图定位

    1.获取Key 参考官方文档:http://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key 对于签名文件的获取建议 ...

  6. android学习十一 高级调试分析功能

    1.debug 功能列表 2.ddms功能( 内存检查,线程检查,视图层次分析) 3.跟踪代码 TraceView 4.命令行工具 adb 5.策略检查StrictMode

  7. 【高德地图Android SDK】视频教学

    前两天参加了高德在北航举办的公开课,感觉非常不错.完成老师布置的作业之后,还顺利地拿到了高德开发者认证证书!! 现在来跟大家分享一下,如何快速学习[高德地图Android SDK]的开发.一天包会!连 ...

  8. 十一、Android学习第十天——项目开始(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 十一.Android学习第十天——项目开始 Android知识点的学习告一 ...

  9. android 高德地图出现【定位失败key鉴权失败】

    如题:android 高德地图出现[定位失败key鉴权失败] 原因:使用的是debug模式下的SHA1,发布的版本正确获取SHA1的方式见: 方法二使用 keytool(jdk自带工具),按照如下步骤 ...

随机推荐

  1. 关于升级xcode8

    升级xcode8已是必然,升级ios10的用户不能说大有人在,应该也不会少,如果不升级xcode8,上架最新的包,那么可能应用在ios10 上是不支持的.so,这些xcode8的新特性,你应该了解!! ...

  2. DateTime 详解

    //2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...

  3. 麦咖啡阻挡正常打开Excel文件

    双击打开Excel文件,提示如下图: Excel文件被麦咖啡做阻挡,无法正常打开 处理方案: 过一会儿还是出现此问题,干脆就把缓冲区保护给禁用掉

  4. Java学习2 - JDK和JRE和JVM的区别_JDK的下载安装_环境变量配置

    一 JDK和JRE和JVM的区别 Jdk: Java Development kit - Java 开发工具 JRE: Java Runtime Environment - java运行环境 JVM: ...

  5. 【Java讨论】引用类型赋值为null对加速垃圾回收的作用(转载)

    :有一些人认为等于null可以帮助垃圾回收机制早点发现并标识对象是垃圾.其他人则认为这没有任何帮助.是否赋值为null的问题首先在方法的内部被人提起.现在,为了更好的阐述提出的问题,我们来撰写一个Wi ...

  6. php递归读取目录

    function recursion_dir($dir){ $files = array(); if($handle = opendir($dir)){ while(($file = readdir( ...

  7. android最常用的退出方法

    public class AppUtils extends Application{ private List<Activity> activityList = new LinkedLis ...

  8. FCKeditor编辑器如何使用

    转自 http://www.cnblogs.com/tylerdonet/archive/2013/04/20/3032980.html

  9. nexus7 二代 升级 android L

    折腾了半天 ,最后发现其实很简单... 1.装好windows下gdb和bootloader的驱动,注意打开usb debug,另外进入bootloader是开机按电源键和音量减小键,至于要解锁这个想 ...

  10. linux命令:df

    1.命令介绍: df用来检测磁盘空间占用情况. 2.命令格式: df [选项] 文件 3.命令参数: 必要参数: -a 全部文件系统列表 -h 方便阅读方式显示 -H 等于“-h”,但是计算式,1K= ...