【发布时间】:2019-05-29 14:30:15
【问题描述】:
我正在开发一个 android 应用程序,其中有包含 Mapview 的片段... 根据本地数据库中的位置包含标记的地图视图.. 有什么方法可以动画甚至更改仅单击标记的颜色? 我的意思是我已经在 setOnMarkerClickListener 中完成了,但是,当我点击另一个标记时,前一个标记仍然是相同的颜色/动画......
添加下面代码的主要部分...
String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
Cursor c = myDataBase.rawQuery("Select * from location", null);
if (c != null) {
if (c.moveToFirst()) {
do {
id = c.getInt(0);
if (userPrefs.getString("locale",null)==null || userPrefs.getString("locale",null).equals("en"))
{
storename = c.getString(1);
}
else {
storename = c.getString(7);
}
stlatitude = c.getDouble(2);
stlongitude = c.getDouble(3);
city = c.getString(4);
String emirate = c.getString(5);
storeloc = new Location("StoreLocation");
storeloc.setLatitude(stlatitude);
storeloc.setLongitude(stlongitude);
addmarker();
}
while (c.moveToNext());
}
}
myDataBase.close();
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
String s= marker.getTitle();
String snippet= marker.getSnippet();
markerlat= marker.getPosition().latitude;
markerlong= marker.getPosition().longitude;
marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
tv.setText(s);
tv1.setText(snippet);
if (s.equals(getActivity().getResources().getString(R.string.here))) {
if (relbutton.getVisibility() == View.VISIBLE && reltext.getVisibility() == View.VISIBLE) {
relbutton.setAlpha(1.0f);
relbutton.animate().translationY(0).alpha(0.0f);
relbutton.setVisibility(View.GONE);
} else if (relbutton.getVisibility() != View.VISIBLE && reltext.getVisibility() != View.VISIBLE) {
reltext.setVisibility(View.VISIBLE);
reltext.setAlpha(0.0f);
reltext.animate().translationY(0).alpha(1.0f);
if (userPrefs.getString("locale",null).equals("ar"))
{
RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.relativeLayout2);
relativeLayout.setGravity(Gravity.LEFT);
RelativeLayout relativeLayout1 = (RelativeLayout) view.findViewById(R.id.relativeLayout1);
relativeLayout1.setGravity(Gravity.RIGHT);
}
}
} else if (relbutton.getVisibility() != View.VISIBLE && reltext.getVisibility() != View.VISIBLE) {
relbutton.setVisibility(View.VISIBLE);
reltext.setVisibility(View.VISIBLE);
reltext.setAlpha(0.0f);
reltext.animate().translationY(0).alpha(1.0f);
relbutton.setAlpha(0.0f);
relbutton.animate().translationY(0).alpha(1.0f);
if (userPrefs.getString("locale",null).equals("ar"))
{
RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.relativeLayout2);
relativeLayout.setGravity(Gravity.LEFT);
RelativeLayout relativeLayout1 = (RelativeLayout) view.findViewById(R.id.relativeLayout1);
relativeLayout1.setGravity(Gravity.RIGHT);
}
} else if (reltext.getVisibility() == View.VISIBLE) {
relbutton.setVisibility(View.VISIBLE);
relbutton.setAlpha(0.0f);
relbutton.animate().translationY(0).alpha(1.0f);
if (userPrefs.getString("locale",null).equals("ar"))
{
RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.relativeLayout2);
relativeLayout.setGravity(Gravity.LEFT);
RelativeLayout relativeLayout1 = (RelativeLayout) view.findViewById(R.id.relativeLayout1);
relativeLayout1.setGravity(Gravity.RIGHT);
}
}
return true;
}
});
directions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nwLocation = appLocationService.getLocation(LocationManager.NETWORK_PROVIDER);
if(nwLocation!=null) {
userlatitude = nwLocation.getLatitude();
userlongitude = nwLocation.getLongitude();
if(markerlat!=null && markerlong!=null) {
String uri = "http://maps.google.com/maps?f=d&hl=en&saddr=" + userlatitude + "," + userlongitude + "&daddr=" + markerlat + "," + markerlong;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
}
}
else {
showSettingsAlert("NETWORK");
}
}
});
return view;
}
private void addmarker() {
markerOptions.position(new LatLng(stlatitude, stlongitude));
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET));
markerOptions.title(getActivity().getResources().getString(R.string.xpressionsstyle));
markerOptions.snippet(storename);
map.addMarker(markerOptions);
}
【问题讨论】:
-
您要在地图屏幕上绘制多少个标记??
-
数据库中位置的数量...
-
所有制造商都应该有不同的颜色??
-
nop... 除了用户位置标记和选定标记外,其他颜色相同...
-
..请检查我的以下解决方案..
标签: android google-maps google-maps-markers