我的代码出了什么问题? 。当我按下按钮时,为什么地图会显示默认位置?
这是我的setOnClickListener
package test;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.core.*;
import org.opencv.imgproc.Imgproc;
import org.opencv.highgui.Highgui;
import java.util.*;
import javax.swing.*;
public class DMImageFactory {
public void contours(String location) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat image =Imgcodecs.imread(location);
Mat dst=new Mat();
Core.inRange(image, new Scalar(0,0,0), new Scalar(255,255,255),dst);
if(dst.empty())
System.out.print("empty matrix");
Imshow im = new Imshow("Box1");
im.showImage(image);
List<MatOfPoint> contours = new ArrayList<>();
Mat countour_result = Mat.zeros(image.size(), CvType.CV_8UC3);
Imgproc.findContours(dst, contours, new Mat(),[enter image description here][1]Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
Imgproc.drawContours(countour_result, contours, -1,new
Scalar(255,255,255));
Imgcodecs.imwrite("/Users/pranay/Desktop/test/counterdetection_intermidiate.png",countour_result);
System.out.print(contours+" ");
for (MatOfPoint contour: contours)
Imgproc.fillPoly(countour_result, Arrays.asList(contour), new Scalar(255,255,255));
Scalar green = new Scalar(81, 190, 0);
for (MatOfPoint contour: contours) {
RotatedRect rotatedRect = Imgproc.minAreaRect(new
MatOfPoint2f(contour.toArray()));
drawRotatedRect(countour_result, rotatedRect, green, 4);
}
Imgcodecs.imwrite("/Users/pranay/Desktop/test/counterdetection.png",countour_result);
}
public static void drawRotatedRect(Mat image, RotatedRect rotatedRect,
Scalar color, int thickness) {
Point[] vertices = new Point[4];
rotatedRect.points(vertices);
MatOfPoint points = new MatOfPoint(vertices);
Imgproc.drawContours(image, Arrays.asList(points), -1, color,
thickness);
}
}
这是我的地图活动:
holder.mapBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v ) {
//if you need position, just use recycleViewHolder.getAdapterPosition();
Toast.makeText(mContext, "OMG! The position is still here and is: "+holder.getAdapterPosition(), Toast.LENGTH_SHORT).show();
Uri uri = Uri.parse("geo:35.2137,31.7683");
Intent intent = new Intent(v.getContext(), MapsActivity.class );
intent.putExtra("location",uri);
mContext.startActivity(intent);
}
});
}
答案 0 :(得分:0)
在OR
方法中,从列表中获取纬度和经度(我在此处仅对其进行了硬编码,仅作为示例)。
onClick
在public void onClick(View v ) {
double lat = 35.2137;
double lng = 31.7683;
Intent intent = new Intent(v.getContext(), MapsActivity.class );
intent.putExtra("lat",lat);
intent.putExtra("lng",lng);
mContext.startActivity(intent);
}
添加实例变量:
MapsActivity
现在,在private LatLng mLatLng;
的{{1}}方法中执行此操作:
onCreate
请注意,-34和151是默认值。您可以选择您喜欢的任何坐标。
现在,您可以使用MapsActivity
方法中的新坐标设置此值:
Intent intent = getIntent();
double lat = intent.getDoubleExtra("lat", -34);
double lng = intent.getDoubleExtra("lng", 151);
mLatLng = new LatLng(lat, lng);