- 浏览: 1503790 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (63)
- android 地图开发,获取经纬度 (5)
- android基于Gps 定位和基站定位获取经纬度 (0)
- ADB server didn't ACK (1)
- android 开发颜色搭配 (2)
- android 设置wifi静态IP及DNS的方法 (2)
- android自定义滑动启动和关闭按钮 (1)
- android listview滑动删除 (2)
- js显示日历 (1)
- android EditText 设计 (1)
- Oracle执行计划详解 (1)
- android 下拉刷新以及加载更多 (1)
- android 技术 (2)
- android 欢迎界面翻页效果 (1)
- Android Animation 动画 (1)
- js 浮动效果 (1)
- android ListView (1)
- android PopupWindow (1)
- android Activity (1)
- android日期选择 (1)
- XML解析 (1)
- android Activity (1)
- JSON详解 (1)
- android 拍照选图 (2)
- android ActivityDialog (1)
- android Activity自定义Dialog (1)
- Android 感应器 (2)
- android 图片压缩 (1)
- Android 多媒体扫描 (2)
- Android 信息推送 (1)
- xmpp及时通讯 (1)
- Android NDK (1)
- android 图片处理 (1)
- android GridView (1)
- android 录音 (1)
- android 目录 (1)
- android Dialog (1)
- Android 屏幕滑动事件 (1)
- Android 数据库操作 (4)
- android插件开发模式 (1)
- TCP/IP 长连接 (1)
- OS操作 (1)
- android 抓包 (1)
- android 网络数据传输 (1)
最新评论
-
cys一:
google api key v2 新的不能使用
android google地图定位开发,且可以自由移动位置重新获取定位,地址信息 -
lmx612:
下载下来可以直接运行,也是我想要的
android listview 下拉刷新以及加载更多 -
tvvbbb:
辛苦楼主了
android 仿微信聊天界面,以及语音录制功能 -
Mandmg:
等了一天.终于下载到了
android 登陆、提交数据或加载数据时提示页面 -
ya1o1123:
android Activity实现从底部弹出或滑出选择菜单或窗口
android google地图定位开发,且可以自由移动位置重新获取定位,地址信息
- 博客分类:
- android 地图开发,获取经纬度
一:申请key:
1.首先找到debug keystore位置:
打开Eclipse--->Windows--->Preferences--->Android--->Build
一般是这样的路径 C:\Documents and Settings\Administrator\.android\debug.keystore
2.在cmd中执行
keytool -list -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator\.android\debug.keystore" -storepass android -keypass android
得到认证指纹 (MD5)如:6F:C9:41:48:A5:F3:36:A5:D3:DD:B5:D1:CB:AC:47:88
3.打开申请key页面 http://code.google.com/android/maps-api-signup.html
复制 认证指纹 (MD5):到下面的 My certificate's MD5 fingerprint
4.然后点击 Generate Api key
5.等到apikey:0Mg_koWoyZUhlluO4-i6-bq9WYMFbxKodZZMz2Q
二:设计main.xml如下:(将申请到得key设置在com.google.android.maps.MapView 中如下所示)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <FrameLayout android:id="@+id/map_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.google.android.maps.MapView android:id="@+id/map_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="0Mg_koWoyZUhlluO4-i6-bq9WYMFbxKodZZMz2Q" android:clickable="true" android:enabled="true" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical" android:paddingBottom="105dip" > <TextView android:id="@+id/map_bubbleText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/location_tips" android:gravity="left|center" android:maxEms="12" android:paddingLeft="12dip" android:paddingRight="10dip" android:text="@string/load_tips" android:textColor="#cfcfcf" android:textSize="14sp" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical" > <ImageView android:id="@+id/point_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="30dip" android:src="@drawable/point_start" /> </LinearLayout> </FrameLayout> </LinearLayout>
三:创建MyLocationManager类主要用于管理经纬度获取方法实现
package com.android.map; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; public class MyLocationManager { private final String TAG = "FzLocationManager"; private static Context mContext; private LocationManager gpsLocationManager; private LocationManager networkLocationManager; private static final int MINTIME = 2000; private static final int MININSTANCE = 2; private static MyLocationManager instance; private Location lastLocation = null; private static LocationCallBack mCallback; public static void init(Context c , LocationCallBack callback) { mContext = c; mCallback = callback; } private MyLocationManager() { // Gps 定位 gpsLocationManager = (LocationManager) mContext .getSystemService(Context.LOCATION_SERVICE); Location gpsLocation = gpsLocationManager .getLastKnownLocation(LocationManager.GPS_PROVIDER); gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINTIME, MININSTANCE, locationListener); // 基站定位 networkLocationManager = (LocationManager) mContext .getSystemService(Context.LOCATION_SERVICE); Location networkLocation = gpsLocationManager .getLastKnownLocation(LocationManager.GPS_PROVIDER); networkLocationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, MINTIME, MININSTANCE, locationListener); } public static MyLocationManager getInstance() { if (null == instance) { instance = new MyLocationManager(); } return instance; } private void updateLocation(Location location) { lastLocation = location; mCallback.onCurrentLocation(location); } private final LocationListener locationListener = new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } public void onLocationChanged(Location location) { Log.d(TAG, "onLocationChanged"); updateLocation(location); } }; public Location getMyLocation() { return lastLocation; } private static int ENOUGH_LONG = 1000 * 60; public interface LocationCallBack{ /** * 当前位置 * @param location */ void onCurrentLocation(Location location); } public void destoryLocationManager(){ Log.d(TAG, "destoryLocationManager"); gpsLocationManager.removeUpdates(locationListener); networkLocationManager.removeUpdates(locationListener); } }
四:创建MyMapOverlay抽象类,并继承Overlay,创建抽象方法
changePoint(GeoPoint newPoint,int type)用于回调重新获取到的GeoPoint 重新定位地图,并获取地址信息
import android.view.MotionEvent; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; //覆盖整个地图捕捉触控事件的OverLay public abstract class MyMapOverlay extends Overlay{ private int point_X; private int point_Y; private GeoPoint newPoint; public MyMapOverlay(int x,int y){ point_X = x; point_Y = y; } boolean flagMove=false; //触控屏幕移动地图,重新根据屏幕中心点获取该点经纬度 @Override public boolean onTouchEvent(MotionEvent event, MapView mapView) { System.out.println("X->"+event.getX()+":"+point_X); System.out.println("Y->"+event.getY()+":"+point_Y); if(event.getAction() == MotionEvent.ACTION_DOWN){ changePoint(newPoint,1); }else if(event.getAction() == MotionEvent.ACTION_UP){ newPoint = mapView.getProjection().fromPixels(point_X,point_Y); changePoint(newPoint,2); } return false; } public abstract void changePoint(GeoPoint newPoint,int type); }
五:MyMapActivity 继承MapActivity类并实现经纬度获取回调接口LocationCallBack 。项目实现如下:
package com.android.googlemap; import java.io.IOException; import java.util.List; import java.util.Locale; import android.graphics.Rect; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.Window; import android.widget.TextView; import com.android.map.MyLocationManager; import com.android.map.MyLocationManager.LocationCallBack; import com.android.map.MyMapOverlay; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; public class MyMapActivity extends MapActivity implements LocationCallBack { private MapView mapView; private MapController mMapCtrl; private MyLocationManager myLocation; private List<Overlay> mapOverlays; public GeoPoint locPoint; private MyMapOverlay mOverlay; private TextView desText; private String lost_tips; private int point_X; private int point_Y; private int statusBarHeight; public final int MSG_VIEW_LONGPRESS = 10001; public final int MSG_VIEW_ADDRESSNAME = 10002; public final int MSG_GONE_ADDRESSNAME = 10003; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.map_view); desText = (TextView) this.findViewById(R.id.map_bubbleText); lost_tips = getResources().getString(R.string.load_tips); mapView.setBuiltInZoomControls(true); mapView.setClickable(true); mMapCtrl = mapView.getController(); point_X = this.getWindowManager().getDefaultDisplay().getWidth() / 2; point_Y = this.getWindowManager().getDefaultDisplay().getHeight() / 2; mOverlay = new MyMapOverlay(point_X, point_Y) { @Override public void changePoint(GeoPoint newPoint, int type) { if (type == 1) { mHandler.sendEmptyMessage(MSG_GONE_ADDRESSNAME); } else { locPoint = newPoint; mHandler.sendEmptyMessage(MSG_VIEW_LONGPRESS); } } }; mapOverlays = mapView.getOverlays(); if (mapOverlays.size() > 0) { mapOverlays.clear(); } mapOverlays.add(mOverlay); mMapCtrl.setZoom(12); MyLocationManager.init(MyMapActivity.this.getApplicationContext(), MyMapActivity.this); myLocation = MyLocationManager.getInstance(); } @Override protected void onResume() { super.onResume(); } @Override protected void onPause() { super.onPause(); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } public void onCurrentLocation(Location location) { if (locPoint == null) { locPoint = new GeoPoint((int) (location.getLatitude() * 1E6), (int) (location.getLongitude() * 1E6)); mHandler.sendEmptyMessage(MSG_VIEW_LONGPRESS); } } public void changePoint(GeoPoint locPoint) { } /** * 通过经纬度获取地址 * * @param point * @return */ private String getLocationAddress(GeoPoint point) { String add = ""; Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); try { List<Address> addresses = geoCoder.getFromLocation( point.getLatitudeE6() / 1E6, point.getLongitudeE6() / 1E6, 1); Address address = addresses.get(0); int maxLine = address.getMaxAddressLineIndex(); if (maxLine >= 2) { add = address.getAddressLine(1) + address.getAddressLine(2); } else { add = address.getAddressLine(1); } } catch (IOException e) { add = ""; e.printStackTrace(); } return add; } /** * * 用线程异步获取 */ Runnable getAddressName = new Runnable() { public void run() { String addressName = ""; while (true) { addressName = getLocationAddress(locPoint); if (!"".equals(addressName)) { break; } } Message msg = new Message(); msg.what = MSG_VIEW_ADDRESSNAME; msg.obj = addressName; mHandler.sendMessage(msg); } }; private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_VIEW_LONGPRESS:// 处理长按时间返回位置信息 { if (null == locPoint) return; new Thread(getAddressName).start(); desText.setVisibility(View.VISIBLE); desText.setText(lost_tips); mMapCtrl.animateTo(locPoint); mapView.invalidate(); } break; case MSG_VIEW_ADDRESSNAME: desText.setText((String) msg.obj); desText.setVisibility(View.VISIBLE); if (statusBarHeight == 0) { Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame( frame); statusBarHeight = frame.top; point_Y -= statusBarHeight / 2; } break; case MSG_GONE_ADDRESSNAME: desText.setVisibility(View.GONE); break; } } }; // 关闭程序也关闭定位 @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); myLocation.destoryLocationManager(); } }
六:在AndroidManifest.xml中不要忘了要添加访问网络和启动定位等的几个权限已经google地图库
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!--在application里面添加google地图库如下(一定要记得添加):--> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="com.google.android.maps" /> <activity android:name="com.android.googlemap.MyMapActivity" android:screenOrientation="portrait" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
七:运行效果:
1
提示:如果没有出现地图只出现地址信息背景是网格的,那就是key的问题,根据开始的方法找到自己开发的eclipse中sdk的debug keystore位置重新申请key即可
评论
国内的地图坐标是火星坐标和gps获取的坐标是不一致的.
发表评论
-
android 基于百度地图api开发定位以及获取详细地址
2012-09-19 22:37 158889一:百度地图开发必须要到百度开发平台android开 ... -
android 基于基站,apn,gps,wifi,network 根据不同手机sim卡获取经纬度
2012-09-18 22:12 6096一:新建MyLocation类,本类主要管理使用各种 ... -
android基于Gps 定位和基站定位获取经纬度
2012-09-18 21:26 12241一:新建MyLocationManager.java ... -
android 基于百度地图api获取经纬度
2012-09-18 20:35 65482一:申请百度地图key 申请key网址:http: ...
相关推荐
《Google Android SDK开发范例大全(第3版)》在上一版的基础上,以Android手机应用程序开发(采用Android SDK 2.3.3)为主题,超过200多个范例全面且深度地整合了手机、网络及服务等多个开发领域,为读者提高程序设计...
《Google Android SDK开发范例大全(第3版)》在上一版的基础上,以Android手机应用程序开发(采用Android SDK 2.3.3)为主题,超过200多个范例全面且深度地整合了手机、网络及服务等多个开发领域,为读者提高程序设计...
《Google Android SDK开发范例大全(第3版)》在上一版的基础上,以Android手机应用程序开发(采用Android SDK 2.3.3)为主题,超过200多个范例全面且深度地整合了手机、网络及服务等多个开发领域,为读者提高程序设计...
百度地图移动获取位置,自动定位.zip 百度快速定位locSDK_3.3_Demo.zip 监控别人的行踪.rar 级联菜单,两级菜单自定义实现提供多种方式PopWindow,Fragment引用..rar 自动判断位置的弹出菜单.zip 菜单动画(类似QQ...
《Google Android SDK开发范例大全(第3版)》在上一版的基础上,以Android手机应用程序开发(采用Android SDK 2.3.3)为主题,超过200多个范例全面且深度地整合了手机、网络及服务等多个开发领域,为读者提高程序设计...
本文实例为大家分享了Android获取位置信息的具体代码,供大家参考,具体内容如下 1.位置服务的简介:位置服务,英文翻译为Location-Based Services,缩写为LBS,又称为定位服务或基于位置的服务,融合了GPS定位、移动...
将会支持 Google 可能发布的手机操作系统或者应用软件,共同开发名为 Android 的开放源代码的移动 系 统。 谷歌早在 2002 年就进入了移动领域,可是由于目前的手机操作系统企业和手机企业相对封闭,提高了 行业的...
Android 一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导开发 IOS 由苹果公司开发的移动操作系统 Webkit 一个开源的浏览器引擎,在手机上的...
本书以Android应用程序的开发为主题,并结合真实的案例向读者详细介绍了Android的基本组件的使用及应用程序开发的整个流程。本书的讲述由浅入深,实例全面并典型,几乎囊括了所有和Android应用相关的项目。全书分为...
该地理定位服务可以用来获取当前设备的地理位置,应用程序可以定时请求更新设备当前的地理位置信息。比如应用程序可以借助一个Intent接收器来实现如下功能: 以经纬度和半径规划一个区域,当设备进入给区域,发出...
此示例展示了如何获取 Android 移动设备(例如手机或平板电脑)的位置和速度数据。 位置数据由纬度、经度和高度数据组成。 在此示例中,捕获的纬度和经度数据在 MATLAB 中绘制,并使用 Mapping Toolbox 覆盖在来自 ...
这是一个集成目前Android主流优秀第三方组件、优秀好用的自定义控件、实用工具类封装、以及一些APP共通模块(比如:版本更新、意见反馈、引导界面等等)的开发包,帮助程序员快速开发自己的APP 已集成第三方开源...
8, GPS 定位,支持获取手机GPS 定位数据,实现GPS 定位监控,以及基站定位; 9, Bing Maps API,支持访问互联网地图服务Bing Maps; 10,Google Maps API,支持访问互联网地图服务Google Maps; 11,数据融合,...
地图定位工具类(ToolLocation.java),读取GPS状态、请求定位、获取经纬度等方法 社会化分享工具类(ToolShareSDK.java),各大开发平台分享API操作 短信验证码工具类(ToolMSM.java),移动/联通/电信三网发送手机...
这是一个集成目前Android主流优秀第三方组件、优秀好用的自定义控件、实用工具类封装、以及一些APP共通模块(比如:版本更新、意见反馈、引导界面等等)的开发包,帮助程序员快速开发自己的APP 已集成第三方开源...
见博客:http://blog.csdn.net/baidu_nod/article/details/37697685
详细来讲,本文所研讨的移动旅行信息管理系统首要包含三个子系统:景点查询,该子系统能供给对旅行景点方位查询,在地图上标识经纬度值,能对当时及未来三天进行天气预报,能查询两地址间的行走搭车途径以及周边住宿、...
My-Life是专为Android平台设计的移动应用程序。 使用不同的智能手机传感器,该软件可以记录白天或锻炼期间用户活动的数据。 收集的信息显示为一组统计信息,并且还以图形或地图的形式显示。 My-Life是由弗罗茨瓦夫...