android item添加图片,怎么在 OverlayItem 中展示 图片和文字

当前位置:我的异常网» Android » 怎么在 OverlayItem 中展示 图片和文字

怎么在 OverlayItem 中展示 图片和文字

www.myexceptions.net  网友分享于:2013-02-01  浏览:408次

如何在 OverlayItem 中展示 图片和文字

package com.mainaer.android.Map;

import java.util.ArrayList;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.Point;

import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;

import com.google.android.maps.MapView;

import com.google.android.maps.Projection;

import com.google.android.maps.OverlayItem;

public class GeoItemizedOverlay extends ItemizedOverlay {

private ArrayList mOverlays = new ArrayList();

public GeoItemizedOverlay(Drawable defaultMarker) {

super( boundCenterBottom(defaultMarker));

}

@Override

protected OverlayItem createItem(int i) {

return mOverlays.get(i);

}

@Override

public int size() {

return mOverlays.size();

}

public void addOverlay(OverlayItem overlay) {

mOverlays.add(overlay);

populate();

}

public void draw(Canvas canvas, MapView mapView, boolean shadow) {

Projection projection = mapView.getProjection();

for (int index = size() - 1; index >= 0; index--) {

OverlayItem overLayItem = getItem(index);

/* 题目 */

String title = overLayItem.getTitle();

/* 简介 */

String snippet = overLayItem.getSnippet();

/* 象素点取得转换 */

Point point = projection.toPixels(overLayItem.getPoint(), null);

/* 目标城市圈出来 */

Paint paintCircle = new Paint();

paintCircle.setColor(Color.YELLOW);

canvas.drawCircle(point.x, point.y, 5, paintCircle);

/* 文字设置 */

Paint paintText = new Paint();

paintText.setColor(Color.RED);

paintText.setTextSize(25);

canvas.drawText(title+snippet, point.x, point.y, paintText);

}

super.draw(canvas, mapView, shadow);

}

}

在 onCreate 里面

调用:

public class WhereToBuy extends MapActivity {

MapView mMap;

TextView mCurrentCityName;

EditText mKey;

ImageButton mSwitchCity;

ImageButton mSearch;

Location mCurrentLocation;

GpsLocationListener mGpsLocation;

MapController mapController;

GeoItemizedOverlay itemizedOverlay;

Drawable drawable;

List mapOverlays;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

initCtrl();

mMap.setBuiltInZoomControls(true);

mMap.setClickable(true);

mMap.setEnabled(true);

GeoPoint point1 = new GeoPoint(19240000, -99120000);

GeoPoint point2 = new GeoPoint(35410000, 139460000);

// 设置初始地图的中心位置

GeoPoint geoBeijing=new GeoPoint((int)(39.95*1000000), (int)(116.37*1000000));

OverlayItem bjItem = new OverlayItem(geoBeijing, "JQQ", "Bei jing Welcome you !!");

OverlayItem overlayitem1 = new OverlayItem(point1, "DHZ", "what are you doing now ?");

overlayitem1.setMarker(drawable);

OverlayItem overlayitem2 = new OverlayItem(point2, "SRH", "where are you from ?");

overlayitem1.setMarker(drawable);

itemizedOverlay.addOverlay(overlayitem1);

itemizedOverlay.addOverlay(overlayitem2);

itemizedOverlay.addOverlay(bjItem);

mapOverlays.add(itemizedOverlay);

mapController.animateTo(geoBeijing);

mapController.setCenter(geoBeijing);

mapController.setZoom(9);

}

protected void initCtrl() {

mMap = (MapView) findViewById(R.id.mMap);

mCurrentCityName = (TextView) findViewById(R.id.mCurrentCity);

mKey = (EditText) findViewById(R.id.mKey);

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值