ANDROID_MARS学习笔记_S03_009_GOOGLEMAP3
一、代码
1.xml
(1)main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="@+id/mapViewId"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0pkT0EYxPi2VZ5beDaJ0g08aCtWGmKTFnOvj6iw"
/>
</LinearLayout>
(2)AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.se7en"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<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>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
2.java
(1)MainActivity.java
package com.se7en; import java.util.List; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.os.Bundle; 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 com.google.android.maps.Projection; public class MainActivity extends MapActivity {
private Projection projection;
private List<Overlay> overlays;
private MapController mapController;
private GeoPoint beginGeoPoint;
private GeoPoint endGeoPoint; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); beginGeoPoint = new GeoPoint(19240000,-99120000);
endGeoPoint = new GeoPoint(19340000,-99220000); MapView mapView = (MapView)findViewById(R.id.mapViewId);
mapView.setBuiltInZoomControls(true); //mapController主要用于对地图进行控制
mapController = mapView.getController();
overlays = mapView.getOverlays();
projection = mapView.getProjection(); overlays.add(new PointOverlay(beginGeoPoint));
overlays.add(new PointOverlay(endGeoPoint));
overlays.add(new LineOverlay(beginGeoPoint,endGeoPoint)); //将地图以动画的形式移动到指定的点
mapController.animateTo(beginGeoPoint);
//设置地图的放大级别
mapController.setZoom(12);
} @Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
} //图标层
class PointOverlay extends Overlay{
private GeoPoint geoPoint;
public PointOverlay(){ }
public PointOverlay(GeoPoint geoPoint){
this.geoPoint = geoPoint;
}
public void draw(Canvas canvas,MapView mapView,boolean shadow){
super.draw(canvas, mapView, shadow);
Point point = new Point();
//将geoPoint转换为屏幕上的X、Y轴坐标
projection.toPixels(geoPoint, point);
//位图
Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.tool);
Paint paint = new Paint();//画笔
//Y轴-30是为了调整图片的显示位置(默认是讲图片的左上角对应到经纬度点)
canvas.drawBitmap(bmp,point.x,point.y-30,paint);
}
} //路线层
class LineOverlay extends Overlay{
private GeoPoint begin;
private GeoPoint end; public LineOverlay(){}
public LineOverlay(GeoPoint begin,GeoPoint end){
this.begin = begin;
this.end = end;
} public void draw(Canvas canvas,MapView mapView,boolean shadow){
super.draw(canvas, mapView, shadow);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
//设置线条的样式(填满的空心线)
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(2);
Point beginPoint = new Point();
Point endPoint = new Point();
Path path = new Path();
projection.toPixels(begin,beginPoint);
projection.toPixels(end,endPoint);
//指定划线的起始点
path.moveTo(beginPoint.x,beginPoint.y);
//指定划线的终点
path.lineTo(endPoint.x,endPoint.y);
canvas.drawPath(path,paint);
}
} }
ANDROID_MARS学习笔记_S03_009_GOOGLEMAP3的更多相关文章
- ANDROID_MARS学习笔记_S01_012_RatingBar
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01_012_SeekBar
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01_011ProgressBar
文档是这样来设置样式 <ProgressBar android:layout_width="wrap_content" android:layout_height=" ...
- ANDROID_MARS学习笔记_S01_010日期时间控件
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01_009Relative_LAYOUT例子
1. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android ...
- ANDROID_MARS学习笔记_S01_008Linear_layout例子
1.netstone_layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...
- ANDROID_MARS学习笔记_S01_007Linear_layout嵌套与layout_weight的设置
一.介绍 二.1.linear_layout.xml <?xml version="1.0" encoding="utf-8"?> <Line ...
- ANDROID_MARS学习笔记_S01_006ImageView
一.ImageView介绍 设置scalType Must be one of the following constant values. Constant Value Description ma ...
- ANDROID_MARS学习笔记_S01_005CheckBox
一. 1.checkbox_layout.xml <?xml version="1.0" encoding="utf-8"?> <Linear ...
随机推荐
- 使用ViewState[""]传递Hashtable的值
//首先定义Hashtable myHach = new Hashtable(); //添加键值到Hashtable中myHash.Add("ServiceType1", &quo ...
- java中数据类型及运算符的注意事项
数据类型: boolean 类型数据只允许取值true 或 false(不可以使用0 或非0的整数来代替true和false,区分于C语言). char:Java中用" \u四位十六进制的数 ...
- ASC码 .
有些时候需要用到一些字符的ASC码,到网上查找太麻烦,现在记录下来. 第128-255号为扩展字符(不常用) Dec Hx Oct Char Dec Hx Oct Char Dec Hx Oct ...
- Web前端/后端
Web前端: 1)精通HTML,能够书写语义合理,结构清晰,易维护的HTML结构. 2)精通CSS,能够还原视觉设计,并兼容业界承认的主流浏览器. ...
- AFNetworking3.0+MBProgressHUD二次封装,一句话搞定网络提示
对AFNetworking3.0+MBProgressHUD的二次封装,使用更方便,适用性非常强: 一句话搞定网络提示: 再也不用担心网络库更新后,工程要修改很多地方了!网络库更新了只需要更新这个封装 ...
- 0基础学习ios开发笔记第一天
Ios操作 界面操作 快捷键 command + c 复制 command+v 粘贴 command +a 全选 command +s 保存 command +z 撤销 command +x 剪切 ...
- WPF动画之路径动画(3)
XAML代码: <Window x:Class="路径动画.MainWindow" xmlns="http://schemas.microsoft.com/winf ...
- Javascript模仿C语言的链表实现(增删改查),并且使用控制台输入输出
Js新手最近在研究Js数据结构,刚好看到链表实现这一块儿,觉得有些资料和自己理解的有冲突,于是借着自己以前一点点C语言的基础,用Javascript模仿了C的链表实现,并且用了process.stdi ...
- storm学习之入门篇(一)
海量数据处理使用的大多是鼎鼎大名的hadoop或者hive,作为一个批处理系统,hadoop以其吞吐量大.自动容错等优点,在海量数据处理上得到了广泛的使用.但是,hadoop不擅长实时计算,因为它天然 ...
- hdu 1286 找新朋友 (欧拉函数)
Problem Description 新年快到了,"猪头帮协会"准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的 ...