Android定位源码.doc_第1页
Android定位源码.doc_第2页
Android定位源码.doc_第3页
Android定位源码.doc_第4页
Android定位源码.doc_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

著作权人:开元福佑(北京)科技有限公司软件名称:一种老年人手机定位监护通信系统软件版本:v3.0 代码长度:16598行AndroidManifest.xml文件配置 Main.java文件package cn.itcast.main;import java.util.List;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;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Point;import android.location.Address;import android.location.Criteria;import android.location.Geocoder;import android.location.Location;import android.location.LocationListener;import android.location.LocationManager;import android.os.Bundle;import android.view.MotionEvent;import android.widget.TextView;public class Main extends MapActivity private MapController mapController; private GeoPoint geoPoint; private String msg; Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); /获得mapview MapView mapView=(MapView) this.findViewById(R.id.mapview); /地图的显示格式为交通图 mapView.setTraffic(true); /设置可控 mapView.setClickable(true); mapView.setEnabled(true); mapView.setBuiltInZoomControls(true); /得到gps设备的访问 LocationManager locationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE); /设置gps定位配置 Criteria criteria=new Criteria(); /设置显示精度 criteria.setAccuracy(Criteria.ACCURACY_COARSE); /是否获得海拔数据 criteria.setAltitudeRequired(false); /是否获得方向数据 criteria.setBearingRequired(false); /是否允许运营商计费 criteria.setCostAllowed(true); /设置耗电程度 criteria.setPowerRequirement(Criteria.POWER_LOW); /获得服务供应商 String provider=locationManager.getBestProvider(criteria, true); /获取上一个定位点 Location location=locationManager.getLastKnownLocation(provider); /获得gps定位坐标信息 Double latitude=location.getLatitude()*1E6; Double longitude=location.getLongitude()*1E6; /获得卫星定位点 geoPoint=new GeoPoint(Value(),Value(); /获得地图控制器 mapController=mapView.getController(); /设置地图显示初始化精度 mapController.setZoom(12); mapController.animateTo(geoPoint); /实例化自定义绘图层 MyOverlay myOverlay=new MyOverlay(); /为mapview添加绘图层 mapView.getOverlays().add(myOverlay); /定义一个final,TextView,以备子类引用 final TextView textView=(TextView) findViewById(R.id.textview); LocationListener locationListener=new LocationListener() Overridepublic void onStatusChanged(String provider, int status, Bundle extras) Overridepublic void onProviderEnabled(String provider) / TODO Auto-generated method stubOverridepublic void onProviderDisabled(String provider) / TODO Auto-generated method stubOverridepublic void onLocationChanged(Location location) Double latitude=location.getLatitude()*1E6;Double longitude=location.getLongitude()*1E6;try /获得精度纬度字符串msg = 经度: + location.getLongitude() + n;msg += 纬度: + location.getLatitude() + n;/根据经纬度获得改点地址信息Geocoder gc=new Geocoder(Main.this);List addresses=gc.getFromLocation(latitude, longitude, 1);if (addresses.size()0) /获得地址信息msg+=AddressLine:+addresses.get(0).getAddressLine(0)+n;/获得国家名msg += CountryName: + addresses.get(0).getCountryName()+n;msg += Locality: + addresses.get(0).getLocality() + n;msg += FeatureName: + addresses.get(0).getFeatureName();textView.setText(msg); catch (Exception e) e.printStackTrace(); /注册位置监听器,1秒钟扫描1次 locationManager.requestLocationUpdates(provider, 1000, 0, locationListener); class MyOverlay extends Overlay /保证触控事件不重复操作 private int count=0;Overridepublic boolean draw(Canvas canvas, MapView mapView, boolean shadow,long when) /定义画笔Paint paint=new Paint();paint.setColor(Color.RED);/定义屏幕点Point screenPoint=new Point();/gps点转屏幕点mapView.getProjection().toPixels(geoPoint, screenPoint);/获得gps标志点图片Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.flag);/绘制gps点图片canvas.drawBitmap(bitmap, screenPoint.x,screenPoint.y, paint);/绘制文字说明canvas.drawText(当前位置, screenPoint.x, screenPoint.y, paint);return super.draw(canvas, mapView, shadow, when);Overridepublic boolean onTouchEvent(MotionEvent e, MapView mapView) /定义一个屏幕点Point screenPoint=new Point();/把gps点变成屏幕点mapView.getProjection().toPixels(geoPoint, screenPoint);/获得触点坐标int currentX=(int) e.getX();int currentY=(int) e.getY();/在50,30范围内触碰,显示当前经纬度if (currentX-screenPoint.x)=0&(currentX-screenPoint.x)=0)&(currentY-screenPoint.y)keytool -list -keystore debug.kEystore 默认密码android - - - - public class LocationClient extends Activity implements LocationListener private static final String TAG = LocationClient.class.getSimpleName(); private static final String S = Out of Service, Temporarily Unavailable, Available ; private TextView output; private LocationManager locationManager; private String bestProvider; private Geocoder geocoder; /* Called when the activity is first created. */ Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); / Get the output UI output = (TextView) findViewById(R.id.output); / Get the location manager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); geocoder = new Geocoder(this); / List all providers: List providers = locationManager.getAllProviders(); for (String provider : providers) printProvider(provider); System.out.print(The providers: + providers); Criteria criteria = new Criteria(); bestProvider = locationManager.getBestProvider(criteria, false); output.append(nnBEST Provider:n); printProvider(bestProvider); output.append(nnLocations (starting with last known):); Location location = locationManager.getLastKnownLocation(bestProvider); printLocation(location); /* Register for the updates when Activity is in foreground */ Override protected void onResume() super.onResume(); locationManager.requestLocationUpdates(bestProvider, 2000, 1, this); /* Stop the updates when Activity is paused */ Override protected void onPause() super.onPause(); locationManager.removeUpdates(this); public void onLocationChanged(Location location) printLocation(location); public void onProviderDisabled(String provider) / let okProvider be bestProvider / re-register for updates output.append(nnProvider Disabled: + provider); public void onProviderEnabled(String provider) / is provider better than bestProvider? / is yes, bestProvider = provider output.append(nnProvider Enabled: + provider); public void onStatusChanged(String provider, int status, Bundle extras) output.append(nnProvider Status Changed: + provider + , Status= + Sstatus + , Extras= + extras); private void printProvider(String provider) LocationProvider info = locationManager.getProvider(provider); Log.d(TAG, Name: + info.getName(); Log.d(TAG, Accuracy: + info.getAccuracy(); Log.d(TAG, Require Cell? + info.requiresCell(); Log.d(TAG, Require Network? + info.requiresNetwork(); Log.d(TAG, Require Satellite? + info.requiresSatellite(); Log.d(TAG, Supports Altitude? + info.supportsAltitude(); Log.d(TAG, Supports Bearing? + info.supportsBearing(); Log.d(TAG, Supports Speed? + info.supportsSpeed(); Log.d(TAG, Power requirement? + info.getPowerRequirement(); Log.d(TAG, Might steal my money?+ info.hasMonetaryCost(); output.append(info.toString() + nn); private void printLocation(Location location) if (location = null) output.append(nLocationunknownnn); else String text = String.format(Latitude:t %f nLongitude:t %fn Altitude:t %fn Bearing:t %fn, location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getBearing(); Log.d(TAG, text); output.append(nn+text); try List addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10); for(Address address: addresses) output.append(n+ address.getAddressLine(0); catch(Exception e) Log.e(WhereAmI, Couldnt get Geocoder data, e); using System;using System.Collections.Generic;using System.Linq;using System.Web;using dedeMapNew.DB;using System.Configuration;using ETS.Framework;using System.IO;using WEB.Common.Settings;using ETS.Framework.UploadHelper;using ETSWebSite.Module.Enums;using dedeBusiness;using dedeModel.Enums;namespace upLoadLibrary / / uploadFile 的摘要说明 / public class uploadFile : IHttpHandler public void ProcessRequest(HttpContext context) string upLoadType = context.RequestupLoadType; int currentUserId = context.RequestUserId.ConvertTo(0); if (currentUserId e.Id = currentUserId); / 判断有没有登陆 switch (upLoadType) case ziyuan: HttpPostedFile upload = context.Request.FilesFiledata; if (upload != null) int upLoadFiledId = context.RequestId.ConvertTo(0); Web_Rec_BInfo currentFilesModel = null; if (upLoadFiledId 0) IQueryable changeFile = dbcontext.Web_Rec_BInfo.Where(e = e.Id = upLoadFiledId); if (changeFile.Count() 0) currentFilesModel = changeFile.First(); else currentFilesModel = null; string rootPath = AppSettings.CommonSetting.GetValue(File/RootPath); int maxSize = ConfigurationManager.AppSettingsLimitSize.ConvertTo(); string fileName = DateTime.Now.Ticks.ToString(); string fileExp = upload.FileName.Substring(upload.FileName.IndexOf(.); string relatePath = File/ + DateTime.Now.Year + / + DateTime.Now.Month + / + currentUserId + /;/paper/日期/UserId/文件名称的格式 string savePath = string.Empty; if (!Directory.Exists(rootPath.CombinRelativePath(relatePath) Directory.CreateDirectory(rootPath.CombinRelativePath(relatePath); string fullPath = rootPath.CombinRelativePath(relatePath + fileName + fileExp); if (currentFilesModel != null) if (currentUserId != currentFilesModel.UserId) throw new Exception(没有权限); else currentFilesModel = new Web_Rec_BInfo(); if (upload != null) if (upload.ContentLength maxSize) throw new Exception(您上传的文件超出规定大小); decimal LeaveSize = CommonBusiness.GetKongJianSize(currentUserId) - CommonBusiness.GetUseSize(currentUserId); if (upload.ContentLength LeaveSize) throw new Exception(空间不足); upload.SaveAs(fullPath); currentFilesModel.Taxonpath = relatePath + fileName + fileExp; currentFilesModel.FileName = fileName; currentFilesModel.FileEXName = fileExp; if (File.Exists(currentFilesModel.Taxonpath) File.Delete(currentFilesModel.Taxonpath); currentFilesModel.FlowerPoint = context.RequestFlowerPoint.ConvertTo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论