我设法从http://kailun92wcf.cloudapp.net/Service1.svc获得了我的wcf服务,但是我需要帮助才能使用它并让xCoord和yCoord在我的地图中绘制它。我设法得到了这个名字,但我仍然坚持从wcf服务中调用xCoord和yCoord。
private void polyc_Checked(object sender, RoutedEventArgs e)
{
var service = new Service1Client();
service.getRecommendPlaceAsync(new getRecommendPlaceRequest { activityId = 2 });
service.getRecommendPlaceCompleted += new EventHandler<MyCloudService.getRecommendPlaceCompletedEventArgs>(RecommendedPlaceRequestComplete);
}
void RecommendedPlaceRequestComplete(object sender, MyCloudService.getRecommendPlaceCompletedEventArgs e)
{
if (e.Error == null)
{
var result = String.Join(",", (from place in e.Result.getRecommendPlaceResult select place.Name).ToArray());
MessageBox.Show(result);
}
else
{
MessageBox.Show("An error occured: " + e.Error.Message);
}
GraphicsLayer graphicsLayer = map.Layers["polyCoords"] as GraphicsLayer;
foreach (Classes.Places location in data)
{
MapPoint point = new MapPoint(Convert.ToDouble(location.XCoord), Convert.ToDouble(location.YCoord));
mcp.Add(location);
ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = point, Symbol = PolyMarkerSymbol };
graphicsLayer.Graphics.Add(graphic);
}
}
答案 0 :(得分:1)
您可以从
中检索地名的同一组结果中获取坐标列表而不是
var result = String.Join(",", (from place in e.Result.getRecommendPlaceResult select place.Name).ToArray());
创建一个类结构,例如
public class Points
{
public decimal XCoordinate { get; set; }
public decimal YCoordinate { get; set; }
}
然后
var coordinates = from place in e.Result.getRecommendPlaceResult select new Points {XCoordinate = place.XCoord, YCoordinate = place.YCoord};
坐标现在应该有你的清单。
你可能更喜欢有一个地方列表,比如
var places = from place in e.Result.getRecommendPlaceResult select place;
然后你可以从列表中的元素中获取任何属性
foreach (var place in places)
{
MessageBox.Show(string.Format("Place: {0} at {1}, {2}", place.Name, place.XCoord, place.YCoord));
}