基本信息
源码名称:android localtion 定位例子
源码大小:2.36KB
文件格式:.java
开发语言:Java
更新时间:2014-09-22
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.yarin.android.MobileMap; import java.io.IOException; import java.util.List; import java.util.Locale; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; import android.location.Address; import android.location.Geocoder; import android.location.Location; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; public class LocationOverlay extends Overlay { private Location mLocation; private MobileMap mMobileMap; private String mAddresses; public LocationOverlay(MobileMap mobileMap) { mMobileMap = mobileMap; } public void setLocation(Location location) { mLocation = location; mAddresses = getAddresses(); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); Paint paint = new Paint(); Point scPoint = new Point(); GeoPoint tmpGeoPoint = new GeoPoint((int)(mLocation.getLatitude()*1E6),(int)(mLocation.getLongitude()*1E6)); mapView.getProjection().toPixels(tmpGeoPoint, scPoint); paint.setStrokeWidth(1); paint.setARGB(255, 255, 0, 0); paint.setStyle(Paint.Style.STROKE); //消除锯齿 paint.setFlags(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(16); Bitmap bmp = BitmapFactory.decodeResource(mMobileMap.getResources(), R.drawable.mark); canvas.drawBitmap(bmp, scPoint.x-bmp.getWidth()/2, scPoint.y-bmp.getHeight(), paint); canvas.drawText(mAddresses, scPoint.x-paint.measureText(mAddresses)/2, scPoint.y, paint); return true; } public String getAddresses() { String addressString="没有找到地址"; Geocoder gc=new Geocoder(mMobileMap,Locale.getDefault()); try { List<Address> addresses=gc.getFromLocation(mLocation.getLatitude(), mLocation.getLongitude(),1); StringBuilder sb=new StringBuilder(); if(addresses.size()>0) { Address address = addresses.get(0); sb.append("地址:"); for (int i = 0; i < address.getMaxAddressLineIndex(); i ) { sb.append(address.getAddressLine(i)); } addressString=sb.toString(); } }catch(IOException e){} return addressString; } }