Board logo

标题: Windows Mobile中的Web Service应用 03 [打印本页]

作者: samwalton    时间: 2014-5-25 17:55     标题: Windows Mobile中的Web Service应用 03

然后我们创建一个FindSpecification对象,指定地图数据库、要查询的地点,然后将其作为FindServiceSoap的Find方法的参数执行查询,并返回FindResults对象中。
FindSpecification myFindSpec = new FindSpecification();

myFindSpec.DataSourceName = "MapPoint.NA";
myFindSpec.InputPlace = this.textBox1.Text;

FindResults results = fws.Find(myFindSpec);
if (0 == results.NumberFound)
{
    MessageBox.Show("你找的是什么鬼地方?");
    return;
}
  我们选择的地图数据源是北美地区的数据集“MapPoint.NA”,而InputPlace是要查询的地点,从界面上的文本框中获得。然后调用FindSpecification的Find方法,返回FindResults对象。如果结果集对象的NumberFound属性为0,则说明没找到合适的结果。
  然后我们创建一个ViewByScale对象,为该对象的CenterPoint属性创建LatLong对象。CenterPoint属性的经纬度分别results.Results[0].FoundLocation.LatLong中的经纬度。然后在ViewByScale对象的 MapScale属性中设置地图的比例尺。创建MapOptions对象,在MapOptions.Format设置地图的宽度和长度。创建一个图钉对象 Pushpin,将图钉对象的经纬度设置为ViewByScale对象的经纬度。
  在创建完这些对象后,我们创建一个MapSpecification对象用于指定要显示地图的详细情况。我们要指定MapSpecification对象的地图数据集,并将前边创建的三个对象分别赋给Options、Pushpins、Views属性中。
MapSpecification myMapSpec = new MapSpecification();

myMapSpec.DataSourceName = "MapPoint.NA";
myMapSpec.Options = options;
myMapSpec.Pushpins = pushpins;
myMapSpec.Views = views;
  在设置完成MapSpecification对象后,我们将其作为参数,调用RenderServiceSoap对象的GetMap方法,获取MapImage对象。然后将MapImage对象中的数据作为MemoryStream内存流,用于创建一个Bitmap对象,最后显示到 PictureBox中。
MapImage[] images = ws.GetMap(myMapSpec);

this.pictureBox1.Image = new System.Drawing.Bitmap(new System.IO.MemoryStream(images[0].MimeData.Bits));
  完整代码如下:
WebProxy proxyObject = new WebProxy(proxy, 80);


// Disable proxy use when the host is local.
proxyObject.BypassProxyOnLocal = true;

// All requests this proxy information.
GlobalProxySelection.Select = proxyObject;

FindServiceSoap fws = new FindServiceSoap();
RenderServiceSoap ws = new RenderServiceSoap();
fws.Credentials = new NetworkCredential(myUserName, myPassword);
ws.Credentials = new NetworkCredential(myUserName, myPassword);

FindSpecification myFindSpec = new FindSpecification();
myFindSpec.DataSourceName = "MapPoint.NA";
myFindSpec.InputPlace = this.textBox1.Text;

FindResults results = fws.Find(myFindSpec);
if (0 == results.NumberFound)
{
    MessageBox.Show("你找的是什么鬼地方?");
    return;
}

ViewByScale[] views = new ViewByScale[1];
views[0] = new ViewByScale();
views[0].CenterPoint = new LatLong();
views[0].CenterPoint.Latitude = results.Results[0].FoundLocation.LatLong.Latitude;
views[0].CenterPoint.Longitude = results.Results[0].FoundLocation.LatLong.Longitude;
views[0].MapScale = 150000;

MapOptions options = new MapOptions();
options.Format = new ImageFormat();
options.Format.Height = this.pictureBox1.Height;
options.Format.Width = this.pictureBox1.Width;

Pushpin[] pushpins = new Pushpin[1];
pushpins[0] = new Pushpin();
pushpins[0].IconDataSource = "MapPoint.Icons";
pushpins[0].IconName = "0";
pushpins[0].Label = results.Results[0].FoundLocation.Entity.Name;
pushpins[0].LatLong = views[0].CenterPoint;
pushpins[0].ReturnsHotArea = true;

MapSpecification myMapSpec = new MapSpecification();
myMapSpec.DataSourceName = "MapPoint.NA";
myMapSpec.Options = options;
myMapSpec.Pushpins = pushpins;
myMapSpec.Views = views;

MapImage[] images = ws.GetMap(myMapSpec);
this.pictureBox1.Image = new System.Drawing.Bitmap(new System.IO.MemoryStream(images[0].MimeData.Bits));




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0