package com.csfv3.maps.views.overlays;
import java.util.ArrayList;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.widget.Toast;
import com.csfv3.maps.tileManagement.TilesManager;
import com.csfv3.poi.POI;
public class POIOverlay extends MapOverlay
{
protected Bitmap poiMarker;
protected Paint bitmapPaint = new Paint();
protected Paint textPaint = new Paint();
protected ArrayList<POI> points = new ArrayList<POI>();
protected ArrayList<Point> absPoints = new ArrayList<Point>();
Context context;
public POIOverlay(TilesManager tilesManager, Context context, Bitmap poiMarker)
{
super(tilesManager);
this.context = context;
this.poiMarker = poiMarker;
textPaint.setColor(Color.BLACK);
textPaint.setTextSize(30);
}
@Override
protected void drawOverlay(Canvas canvas, int x, int y)
{
for (POI poi : points)
{
if (!poi.isVisible()) continue;
Point poiPos = tilesManager.lonLatToPixelXY(poi.getLongitude(), poi.getLatitude());
int finalX = poiPos.x + x;
int finalY = poiPos.y + y;
canvas.drawBitmap(poiMarker, finalX - poiMarker.getWidth() / 2, finalY - poiMarker.getHeight() / 2, bitmapPaint);
// canvas.drawText(poi.getName(), finalX - poiMarker.getWidth() / 2,
// finalY, textPaint);
}
}
public void addPoint(POI point)
{
if (point == null) return;
for (POI p : points)
{
if (p.getID() == point.getID()) return;
}
points.add(point);
absPoints.add(tilesManager.lonLatToPixelXY(point.getLongitude(), point.getLatitude()));
}
@Override
public void onClick(double longitude, double latitude)
{
Intent myIntent = new Intent(POIOverlay.this, Infopoi.class);
POIOverlay.this.startActivity(myIntent);
POIOverlay.this.finish();
Point abs = tilesManager.lonLatToPixelXY(longitude, latitude);
float r = poiMarker.getWidth() / 2;
for (Point p : absPoints)
{
if (Math.abs(abs.x - p.x) <= r && Math.abs(abs.y - p.y) <= r)
{
int duration = 8;
Toast.makeText(context, points.get(absPoints.indexOf(p)).getIcon(),Toast.LENGTH_LONG).show();
for (int i = 0; i < duration; i++) {
Toast.makeText(context, points.get(absPoints.indexOf(p)).getInfo(), Toast.LENGTH_LONG).show();
}
return;
}
}
}
@Override
public void onMapZoomChanged(int zoom)
{
absPoints.clear();
for (POI p : points)
{
absPoints.add(tilesManager.lonLatToPixelXY(p.getLongitude(), p.getLatitude()));
}
super.onMapZoomChanged(zoom);
}
}
我使用意图在&#34; pubblic void on click&#34;之后开始新活动。但android studio报告错误并没有启动新活动为什么???请帮忙 !!!我所有的尝试都失败了..infopoi.class没有加载
更新... 2015年10月3日
是的,我在清单中声明...但我没有登录猫因为我已经强调了所有方法..在android studio ..(POIOverlay.this,Infopoi.class)下划线红色他的报告此错误:无法解析构造函数&#39; Intent(com.cfsv3.maps,views.overlays.POiOverlay,java.lang.Class)&#39;在POIOverlay.this.startActivity(myIntent); startactivity是红色的,错误是:无法解析方法startActivity(android.content.Intent)&#39;我也尝试添加公共void onClick(双经度,双纬度)实现OnClickListener我有一个错误实现他的报告红色:工具中的意外令牌和OnClickListener说红色无法解析符号。 需要帮助!
答案 0 :(得分:0)
您没有实现OnClickListener
implements OnClickListener
你也没有设置OnClickListener
.setOnClickListener(this);