gpt4 book ai didi

java - 如何使用 OSMDROID/OSMBonusPack 更改标记气泡

转载 作者:搜寻专家 更新时间:2023-11-01 09:47:43 27 4
gpt4 key购买 nike

我正在尝试用 OSM map 替换我的应用程序中的谷歌地图。我一直在尝试使用 this按照他们如何使用 Jitpack 安装和导入项目。它工作正常。点击标记默认信息气泡(一些浅灰色的)显示。如果我想修改标记气泡的背景,我该怎么办?我的代码中没有使用任何类型的 onClick 方法

 import android.app.Fragment;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import java.util.ArrayList;
import java.util.List;
import demo.exe.exe.R;
import demo.exe.exe.model.Education.EducationServiceProviderItem;
import demo.exe.exe.utils.AppConstants;


public class MapFragmentOSM extends Fragment implements View.OnClickListener {

private ArrayList<EducationServiceProviderItem> educationServiceProvider=null;
MapView mapView;
int subcategotyId;
View rootView;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

double latDouble,longDouble;
int i=0;
super.onCreate(savedInstanceState);
rootView = inflater.inflate(R.layout.fragment_map, container,
false);

mapView = (MapView) rootView.findViewById(R.id.mapview);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
mapView.setUseDataConnection(true);

;
mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);

IMapController mapViewController = mapView.getController();



if(locationNameId==1) {

mapViewController.setZoom(18);
mapViewController.setCenter(AppConstants.BAUNIA1);
}
else if(locationNameId==2)
{
mapViewController.setZoom(17);
mapViewController.setCenter(AppConstants.PARIS1);
}
switch (categoryId)
{
case AppConstants.EDUCATION:
if(educationServiceProvider!=null) {
for (EducationServiceProviderItem et : educationServiceProvider) {
// LatLng location = new LatLng(Double.parseDouble(et.getLatitude()), Double.parseDouble(et.getLongitude()));
subcategotyId = et.getEduSubCategoryId();
latDouble=Double.parseDouble(et.getLatitude());
longDouble=Double.parseDouble(et.getLongitude());
GeoPoint point= new GeoPoint(latDouble,longDouble);
drawMarkerEdu(point, et.getEduNameEng(),et.getAddress(), et.getEduSubCategoryId());
}
}
break;


default:
break;

}

//Add Scale Bar
ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(mapView);
mapView.getOverlays().add(myScaleBarOverlay);


return rootView;
}
private void drawMarkerEdu(GeoPoint point,String title,String address,int subcategotyId) {
Marker marker = new Marker(mapView);
marker.setPosition(point);
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);


if (subcategotyId >= 1 && subcategotyId <= 12)
marker.setIcon(this.getResources().getDrawable(R.drawable.pin_feroza));
else if (subcategotyId >= 13 && subcategotyId <= 17)
marker.setIcon(this.getResources().getDrawable(R.drawable.pin_blue));
else if (subcategotyId >= 18 && subcategotyId <= 19)
marker.setIcon(this.getResources().getDrawable(R.drawable.pin_pink));
else if (subcategotyId >= 20 && subcategotyId <= 21)
marker.setIcon(this.getResources().getDrawable(R.drawable.pin_green));
else if (subcategotyId >= 22 && subcategotyId <= 26)
marker.setIcon(this.getResources().getDrawable(R.drawable.pin_yellow));
marker.setSnippet(title);
marker.setSubDescription(address);
mapView.getOverlays().add(marker);


}
@Override
public void onClick(View v) {

}
}

任何建议将不胜感激!

最佳答案

This tutorial显示你想要的。基本上,您可以覆盖 InfoWindow 类并为其提供您自己的布局。

关于java - 如何使用 OSMDROID/OSMBonusPack 更改标记气泡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37158535/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com