所以我要做的是当用户点击谷歌地图标记时,活动将显示将显示该标记内的所有信息。但问题是,所有标记都显示相同的结果(这是我的parse.com数据库第一行中的项目)。我目前正在使用Xamarin进行开发。我会感激任何答案。先谢谢你们。
public async void getGeoPoint(){
string getPlaceName, getPlacePrice, getPlaceAddress, getOwnerContact, getRentalType, getOwnerName;
string xx = autoCompleteTextView.Text;
ParseQuery<ParseObject> query = ParseObject.GetQuery ("Rentals")
.WhereEqualTo ("rentalCity", xx);
IEnumerable<ParseObject> results = await query.FindAsync ();
foreach(var temp in results){
getLatitude = temp.Get<double> ("rentalLatitude");
getLongitude = temp.Get<double> ("rentalLongitude");
getPlaceName = temp.Get<string> ("rentalName");
getPlacePrice = temp.Get<string> ("rentalPrice");
getPlaceAddress = temp.Get<string> ("rentalFullAddress");
getOwnerContact = temp.Get<string> ("ownerContactNo");
getRentalType = temp.Get<string> ("rentalType");
getOwnerName = temp.Get<string> ("ownerName");
myMarker = map.AddMarker(new MarkerOptions()
.SetPosition(new LatLng(getLatitude, getLongitude))
.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.edimeow))
);
}
map.MarkerClick += (object sender, GoogleMap.MarkerClickEventArgs e) => {
string selected = getPlaceName;
var passToRentalProfile = new Intent (this, typeof(HostRentalProfileList));
passToRentalProfile.PutExtra ("selected", selected);
StartActivity (passToRentalProfile);
this.Finish();
};
btnList.Click += (object sender, EventArgs e) => {
var passToUserList = new Intent (this, typeof(UserListMode));
passToUserList.PutExtra("arrData", xx);
StartActivity(passToUserList);
this.Finish();
};
}//getGeoPoint
答案 0 :(得分:0)
在foreach
循环中,您枚举所有返回的结果,当您在不同的地理位置添加新地图标记时,您不会在添加的标记中存储任何其他详细信息。< / p>
随后,当您枚举下一个结果时,将本地变量重置为新信息。
您的map.MarkerClick
是任何地图标记点击的通用处理程序。
您尝试引用之前设置的getPlaceName
,并且始终等于结果中的最后一项。
您需要将这些结果存储在某个集合中,并将一些ID添加到创建的地图标记中,这样您可以在点击地图标记时返回原始结果。
答案 1 :(得分:0)
我有类似的东西,我需要在单击标记时显示自定义消息,我将其存储在字典中,然后存储在GoogleMap.IOnMarkerClickListener上,它将传递已单击的标记。
公共类MarkerManager:Java.Lang.Object,GoogleMap.IOnMarkerClickListener {
private readonly GoogleMap _map;
private Dictionary<Marker, int> _markerDictionary;
public MarkerManager(GoogleMap map, BaseActivity activity)
{
_activity = activity;
_map = map;
_markerDictionary = new Dictionary<Marker, int>();
}
public void AddMarkerCallback(LatLng position, string title, string bodyText, int? icon, Action<int, Marker> callback,
bool draggable = false, int id = 0)
{
var markerOptions = new MarkerOptions();
markerOptions.SetPosition(position);
markerOptions.SetTitle(title);
markerOptions.SetSnippet(bodyText);
markerOptions.Draggable(draggable);
CallBack = callback;
if (icon.HasValue)
{
markerOptions.InvokeIcon(BitmapDescriptorFactory.FromResource(icon.Value));
}
var marker = _map.AddMarker(markerOptions);
_markerDictionary.Add(marker, id);
_map.SetOnMarkerClickListener(this);
}
public void ClearMap()
{
if(_map != null)
_map.Clear();
_markerDictionary = new Dictionary<Marker, int>();
}
public bool OnMarkerClick(Marker p0)
{
p0.ShowInfoWindow();
Console.WriteLine("maker click");
HideMarkerAfterTime(p0);
foreach (var i in _markerDictionary)
{
if (!i.Key.Equals(p0)) continue;
if (CallBack == null) return true;
SeletedMarkerId = i.Value;
CallBack(i.Value, p0);
return true;
}
if (CallBackLocation != null)
CallBackLocation(p0.Position);
return false;
}
/// <summary>
/// The timer
/// </summary>
private System.Timers.Timer _timer;
/// <summary>
/// Hides the marker after time.
/// </summary>
/// <param name="p0">The p0.</param>
/// <param name="miliSeconds">The mili seconds.</param>
private void HideMarkerAfterTime(Marker p0, double miliSeconds = 3000)
{
//need to clean down timer object. if i click on another
//icon wierd things happen
if (_timer != null) _timer.Dispose();
_timer = new System.Timers.Timer { Interval = miliSeconds };
_timer.Start();
_timer.Elapsed += (sender, args) => _activity.RunOnUiThread(() =>
{
p0.HideInfoWindow();
_timer.Stop();
});
}
}