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 ...
随机推荐
- magento flat和eav表连接的不同
对于flat表,也就是普通的表,例如订单之类的sales_flat_order,这类型的连接,Collection连接 $table = Mage::getSingleton('core/resour ...
- Power Map 更新日志
2015-05-18,五月更新 Custom Regions feature,允许用户自定义区域要素,支持kml和shape格式 New customization features,包括图例/文本框 ...
- WinEdit7 破解方法
最近遇到了winEdit7 超过试用期的问题,找了下解决方案. 这个靠谱,通过在每次退出时自动删除注册表信息,达到无限试用的目的: https://lttt.blog.ustc.edu.cn/2012 ...
- c编程:提示用户输入一个0—9的数字进行猜测电脑产生的随机数。一共有三次机会。
// // main.c // 使用c语言进行编程: 题目:由电脑生成一个由0-9之间的随机数,提示用户也输入一个数字进行猜测.当猜测三次仍不中的时候结束程序. 编译环境:Xcode6.3 特别介 ...
- webapi之jsonp调用
定义跨域handle public class CorsHandler : DelegatingHandler { const string Origin = "Origin"; ...
- node.js 小爬虫 imooc 2016.03.06
爬虫目标:获取http://www.imooc.com/learn/348网页中的章节标题和视频信息. var http = require('http'); var cheerio = requir ...
- Java实战之01Struts2-02配置文件
三.Struts2的配置文件 1.加载时机: 当应用被tomcat加载的时候,struts2的配置文件就已经被加载过了. 2.加载顺序 顺序 配置文件名 所在位置 说明 1 default.prope ...
- SGU 239.Minesweeper
题意: 如图,一列未知的区域长度为n(≤1000),给出第二列的数字,求区域中雷的排列有多少种. Solution: 搜索.这题看上去1000的范围很大,实际上加上合理的剪枝,状态数会变得非常非常少. ...
- hrbust 1328 相等的最小公倍数(数论)
Description 定义An为1,2,-,n的最小公倍数,例如,A1 = 1,A2 = 2,A3 = 6,A4 = 12,A5 = 60,A6 = 60. 请你判断对于给出的任意整数n,An是否等 ...
- CentOS 6.4 64位 安装 jdk 6u45
准备: 1.下载历史版本jdk 地址: http://java.sun.com/products/archive/ 下载的版本 jdk-6u45-linux-x64-rpm.bin Linux x6 ...