google map 定位当前位置和根据手机的方向调整在地图的方向
查遍整个 mapview 相关的文档没有找到与方向有关的方法
后惊觉有 MyLocationOverlay 类能实现了大部分功能
但图旋转始张无法解决
最后只能出绝招了 重载此类
最后实现了此功能
互联网 信息聚合网站 : www.yidin.net 聚合互联网最优质资源、协助设计、分享经验、提升自我 欢迎访问(投稿,招聘信息请入)
欢迎各位同学加入 android 技术二群 222392467
** * 将google 地图的圆点变为带箭头的图标并随方向<a href="http://yidin.net/discuz/forum.php?mod=viewthread&tid=15&extra=page%3D1">转动</a> * @author cola * */ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Point; import android.location.Location; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; import com.google.android.maps.MyLocationOverlay; public class MyCustomLocationOverlay extends MyLocationOverlay { private Context mContext; private float mOrientation; Bitmap arrowBitmap;//图片资源 public MyCustomLocationOverlay(Context context, MapView mapView,Bitmap res) { super(context, mapView); this.arrowBitmap = res; mContext = context; } @<a href="http://yidin.net/discuz/forum.php?mod=viewthread&tid=15&extra=page%3D1">Override</a> protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) { // translate the GeoPoint to screen pixels Point screenPts = mapView.getProjection().toPixels(myLocation, null); // create a rotated copy of the marker //Bitmap arrowBitmap = BitmapFactory.decodeResource( //mContext.getResources(), res); Matrix matrix = new Matrix(); matrix.postRotate(mOrientation); Bitmap rotatedBmp = Bitmap.createBitmap(arrowBitmap, 0, 0, arrowBitmap.getWidth(), arrowBitmap.getHeight(), matrix, true); // add the rotated marker to the canvas canvas.drawBitmap(rotatedBmp, screenPts.x - (rotatedBmp.getWidth() / 2), screenPts.y - (rotatedBmp.getHeight() / 2), null); } public void setOrientation(float newOrientation) { mOrientation = newOrientation; } }
原发贴地址:
google map 定位当前位置和根据手机的方向调整在地图的方向...
http://yidin.net/discuz/forum.php?mod=viewthread&tid=15&fromuid=1