【发布时间】:2020-07-27 02:45:35
【问题描述】:
在我的应用程序中,我有包含 imagview 的 recyclerview,并且此 imageview 通过使用我存储在 sqlite 中的坐标包含静态地图图像。当我单击该图像时,我将该坐标以字符串数组格式传递给其他地图活动,然后再次使用此字符串数组坐标绘制静态地图保存到谷歌地图中的相同多边形。但我不明白该怎么做。
我尝试了以下代码但无法正常工作:
这是我的适配器类的代码,我在图像视图上显示静态地图,然后使用意图将坐标传递给地图活动
String url ="https://maps.googleapis.com/maps/api/staticmap?";
url+="&zoom=18";
url+="&size=300x300";
url+="&maptype=satellite";
url+="&path=color:green|fillcolor:0xFFFF0033|"+ Coordinates;
url+="&key=" + "AIzaSyCj80x6E****Lx_KFsHKlogV0";
Picasso.get().load(url).into(holder.poly_image);
holder.poly_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mCtx, EditMapsActivity.class);
i.putExtra("img", Poly_Coords);
mCtx.startActivity(i);
}
});
这是我想使用坐标绘制多边形的地图活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_maps);
// Obtain the SupportMapFragment and get notified when the map is ready
to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.mapView);
mapFragment.getMapAsync(EditMapsActivity.this);
Intent intent = getIntent();
String staticPolyCoords = intent.getStringExtra("img");
Log.d("Log", "Polygon Coords" + staticPolyCoords);
String answer = staticPolyCoords;
ArrayList<Location> arrayListLatLng = new ArrayList<>();
answer = answer.replace("lat/lng: (" , "");
answer = answer.replace(")" , "");
answer = answer.replace("]","");
answer = answer.replace("[","");
String[] arrayLatLng = answer.split(",");
Log.d("LOG_TAG", "Polygon Coordinates" + arrayLatLng);
for(int i = 0 ; i < arrayLatLng.length ; i++ ){
LatLng Cooordinate_Point = new
LatLng((Double.parseDouble(arrayLatLng[i])),
Double.parseDouble(arrayLatLng[i+1]));
Log.d("LOG_TAG", "Polygon Coordinates" + Cooordinate_Point);
latLngList.add(Cooordinate_Point);
}
然后在map ready方法()中
@Override
public void onMapReady(GoogleMap googleMap) {
myMap = googleMap;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
DrawPolygon(latLngList);
}
private void DrawPolygon(List<LatLng> latLngList) {
/* myMap.addPolygon(new PolygonOptions().strokeColor(Color.GREEN).fillColor(0x7F228B22).add(latLngList));*/
Polygon polygon = myMap.addPolygon(new PolygonOptions()
.clickable(true)
.add(latLngList));
// Store a data object with the polygon, used here to indicate an arbitrary type.
polygon.setTag("alpha");
polygon.setStrokeWidth(3);
polygon.setStrokeColor(Color.GREEN);
polygon.setFillColor(0x7F228B22);
}
【问题讨论】:
-
您想在您自己的活动中加载包含
MapView的网址? -
你应该在 webview 而不是 imageview 中加载 url
-
@GiorgioAntonioli 是的
-
我认为这很简单。访问此网站Polygon Tutorial
标签: java android polygon google-static-maps