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 ...
随机推荐
- 【腾讯Bugly干货分享】总结一个技术总监的教训和经验
本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/Ry-G0Nikh6m-h3ZVC2cLyQ 导语 20 ...
- SQL SERVER格式化字符串位数,不足补零
本文举例在SQLSERVER中将1格式化为001的方法: 1.方法一SQL语句执行如下: ,) as col 2.方法二SQL语句执行如下: ,) ,) as col 下面是C#代码实现方法: ; & ...
- ASP和PHP限制IP访问 只允许指定IP访问 允许*号通配符过滤IP
/** * 检测访问的ip是否为规定的允许的ip * Enter description here ... */ function check_ip(){ $ALLOWED_IP=array('192 ...
- oracle 11g不能连接报ORA-12537+ora-609解决
操作系统: windows2008 数据库:oracle11g 问题发生:一套正常跑了一年的应用系统,忽然无法连接上数据库,但是另外一个应用可以正常链接,数据入库正常. 数据库服务器端查看: 使用 l ...
- Ext.Net学习笔记03:Ext.Net MessageBus用法
发布和订阅消息 Ext.Net MessageBus 的本质是一个消息订阅机制,ExtJS中没有这种机制,所以MessageBus的Ext.Net实现的,但并不是原创,这种功能在dojo中早就实现了, ...
- ASP.NET跨页面传值技巧
1 使用QueryString变量 QueryString是一种非常简单的传值方式,他可以将传送的值显示在浏览器的地址栏中.如果是传递一个或多个安全性要求不高或是结构简单的数值时,可以使用 ...
- linux采用模块方法,添加一个新的设备
该文转载自:http://rangercyh.blog.51cto.com/1444712/521244 系统调用是操作系统内核和应用程序之间的接口,而设备驱动程序是操作系统内核和机器硬件之间的接口. ...
- 项目中logger、message错误信息的配置
申明:在一个项目中必不可少的是Logger和错误信息的配置,现在给出在我们常用的处理方法. —.创建一个ConfigUtils类和他对应的rah.properties文件和Test测试类 Config ...
- [python] virtualenv下解决matplotlib中文乱码
1. 安装中文字体 一般系统自带wqy-microhei,其ttc文件位于/usr/share/fonts/truetype/wqy/wqy-microhei.ttc 2. 将ttc文件复制到pyth ...
- 青瓷qici - H5小游戏 抽奖机 0 创建工程
安装运行平台需要nodejs,具体方法请参照官方说明文档. 运行后打开了一个空空的窗口. 首先我们进行工程设置,菜单>工程>设置 菜单里面设置我们游戏的名称,到时候会显示在游戏的title ...