ANDROID_MARS学习笔记_S03_008_GOOGLEMAP2
一、简介
二、代码
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
- <uses-permission android:name="android.permission.INTERNET" />
2.java
(1)MainActivity.java
- package com.se7en;
- import java.util.List;
- import android.graphics.drawable.Drawable;
- import android.os.Bundle;
- import com.google.android.maps.GeoPoint;
- import com.google.android.maps.MapActivity;
- import com.google.android.maps.MapView;
- import com.google.android.maps.Overlay;
- import com.google.android.maps.OverlayItem;
- public class MainActivity extends MapActivity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- MapView mapView = (MapView)findViewById(R.id.mapViewId);
- //设置mapView显示用于缩放的工具条
- mapView.setBuiltInZoomControls(true);
- Drawable drawable = getResources().getDrawable(R.drawable.index);
- FirstOverlay firstOverlay = new FirstOverlay(drawable,this);
- //创建一个GeoPoint对象,用于通过经纬度指定地图上的一个点
- GeoPoint point = new GeoPoint(19240000,-99120000);
- //创建一个OverlayItem对象,代表图层上的一个标记
- OverlayItem overlayItem = new OverlayItem(point,"hola,mundo!","I'm in china!");
- firstOverlay.addOverlay(overlayItem);
- //调用MapView对象的getOverlays(),得到所有的图层对象
- List<Overlay> mapOverlays = mapView.getOverlays();
- mapOverlays.add(firstOverlay);
- }
- @Override
- protected boolean isRouteDisplayed() {
- // TODO Auto-generated method stub
- return false;
- }
- }
(2)FirstOverlay.java
- package com.se7en;
- import java.util.ArrayList;
- import android.app.AlertDialog;
- import android.app.Dialog;
- import android.content.Context;
- import android.graphics.drawable.Drawable;
- import com.google.android.maps.ItemizedOverlay;
- import com.google.android.maps.OverlayItem;
- /**
- * 在MapView之上创建一个图层,需要创建一个类,实现Overlay,并生成该类的对象,然后将该对象添加到MapView.getOverlays()中;
- * 一个overlayItem对象就代表了一个在地图上显示的标记
- * @author se7en
- *
- */
- public class FirstOverlay extends ItemizedOverlay<OverlayItem>{
- //创建一个List对象,用于持有该图层当中所有的标记对象
- private ArrayList<OverlayItem> overlayItems = new ArrayList<OverlayItem>();
- private Context context;
- public FirstOverlay(Drawable defaultMaker) {
- super(boundCenter(defaultMaker));
- }
- /**
- * @param defaultMaker 指定标记所使用的默认图片
- * @param context
- */
- public FirstOverlay(Drawable defaultMaker,Context context) {
- //boundCenter(defaultMaker):将要标记的经纬度点放在defaultMaker的正下方
- super(boundCenter(defaultMaker));
- this.context = context;
- }
- //用于将生成好的overlayItem对象添加到List当中
- public void addOverlay(OverlayItem overlayItem){
- overlayItems.add(overlayItem);
- //为新添加进来的overlayItem统一执行相关的操作(具体待考证。。。)
- populate();
- }
- //用于创建一个OverlayItem对象
- @Override
- protected OverlayItem createItem(int i) {
- // TODO Auto-generated method stub
- return overlayItems.get(i);
- }
- //返回当前的Overlay当中所包含的overlayItem对象
- @Override
- public int size() {
- // TODO Auto-generated method stub
- return overlayItems.size();
- }
- //当用户点击标记执行的操作
- @Override
- public boolean onTap(int index) {
- OverlayItem item = overlayItems.get(index);
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(item.getTitle());
- builder.setMessage(item.getSnippet());
- Dialog dialog = builder.create();
- dialog.show();
- return true;
- }
- }
ANDROID_MARS学习笔记_S03_008_GOOGLEMAP2的更多相关文章
- 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 ...
随机推荐
- Git之路--1
昨天下午到今天早上,终于搞定了github.过程很难过,不过看到自己的github上有代码了.还是小小的开心了一下.暂时没时间分享相关技术,附带微博链接,有想试试上传上Github的小伙伴可以查看我的 ...
- nyoj349 poj1094 Sorting It All Out(拓扑排序)
nyoj349 http://acm.nyist.net/JudgeOnline/problem.php?pid=349poj1094 http://poj.org/problem?id=10 ...
- DES加密与解密在GET请求时解密失败的问题
DES加密与解密在GET请求时解密失败的问题 在数据进行加密后传递会更安全,但可能有个问题:就是Url编码问题,如果不对Url进行编码直接加密,那么在解密时,如果字符串存在 “+”,这种特殊符号,在解 ...
- C# 日期转换函数
string.Format("{0:d}",dt);//2005-11-5 string.Format("{0:D}",dt);//2005年11月5日 str ...
- 手把手教你写电商爬虫-第四课 淘宝网商品爬虫自动JS渲染
版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 手把手教你写电商爬虫-第三课 ...
- Windows下ANSI、Unicode、UTF8字符编码转换
主意:输入字符串必须是以'\0'结尾,如果输入字符串没有以'\0'结尾,请手动设置,否则转换会有错误. unsigned int EncodeUtil::AnsiToUcs2( char* pAnsi ...
- ECMA5.1中Object.seal()和Object.freeze()的区别
1 Object.seal(O)的调用 When the seal function is called, the following steps are taken: If Type(O) i ...
- 远程mysql出现ERROR 1130 (HY000): Host '172.17.42.1' is not allowed to connect to this MySQL server
ERROR 1130: Host ***.***.***.*** is not allowed to connect to this MySQL server 说明所连接的用户帐号没有远程连接的权限, ...
- nodejs -formidable模块实现图片上传。
var form = new formidable.IncomingForm(); form.uploadDir="/localnonobank/test/images/"; ...
- Java Servlet 回顾
一.转发请求RequestDispatcher 使用request域对象把数据带给转发资源,与重定向的区别:客户端只发出一次请求,服务器端调用多个资源,客户端浏览器地址栏没改变:转发是一次请求,使用的 ...