⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 GpRS与语音配合的 mobile程序 可以语音搜索GPRS的定位位置
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// tabPage4
			// 
			this.tabPage4.Controls.Add(this.btnMoveNext);
			this.tabPage4.Controls.Add(this.btnMovePrevious);
			this.tabPage4.Controls.Add(this.pbRouteMap);
			this.tabPage4.Location = new System.Drawing.Point(4, 4);
			this.tabPage4.Size = new System.Drawing.Size(232, 222);
			this.tabPage4.Text = "Route Map";
			// 
			// btnMoveNext
			// 
			this.btnMoveNext.Location = new System.Drawing.Point(120, 200);
			this.btnMoveNext.Size = new System.Drawing.Size(96, 20);
			this.btnMoveNext.Text = "Move Forward";
			this.btnMoveNext.Click += new System.EventHandler(this.btnMoveNext_Click);
			// 
			// btnMovePrevious
			// 
			this.btnMovePrevious.Location = new System.Drawing.Point(8, 200);
			this.btnMovePrevious.Size = new System.Drawing.Size(104, 20);
			this.btnMovePrevious.Text = "Move Backward";
			this.btnMovePrevious.Click += new System.EventHandler(this.btnMovePrevious_Click);
			// 
			// pbRouteMap
			// 
			this.pbRouteMap.Location = new System.Drawing.Point(8, 1);
			this.pbRouteMap.Size = new System.Drawing.Size(216, 192);
			// 
			// Form1
			// 
			this.Controls.Add(this.tcMap);
			this.Menu = this.mainMenu1;
			this.Text = "Map Point";

		}
		#endregion
		static void Main() 
		{
			Application.Run(new Form1());
		}


		//Variables used by FindAddress and MakeMap methods.
		private string myUserName="38046";
		private string myPassword="~E1}2@+.]l";
		private ViewByHeightWidth[]  views = null;
		private FindResults foundAddressResults;
		private LatLong[] latlongs = null;
		private System.Drawing.Bitmap[] m_Maps;
		private int Position=0;

		private void MakeAddress()
		{
			//Declare variables
			FindServiceSoap findService = new FindServiceSoap();
			Address myAddress =  new Address();
			FindAddressSpecification findAddressSpec = new FindAddressSpecification();

			//
			findService.Credentials= new System.Net.NetworkCredential(myUserName,myPassword);
			findService.PreAuthenticate = true;

			//
			myAddress.AddressLine = txtAddress.Text;		
			myAddress.PrimaryCity = txtCity.Text;
			myAddress.PostalCode = txtPostCode.Text;
			myAddress.CountryRegion = "UK";
		
			//
			findAddressSpec.DataSourceName = "MapPoint.EU";
			findAddressSpec.InputAddress = myAddress;	

			//
			foundAddressResults = findService.FindAddress(findAddressSpec);

			//
			views = new ViewByHeightWidth[1];
			views[0] = foundAddressResults.Results[0].FoundLocation.BestMapView.ByHeightWidth;
		}

		private void MakeMap()
		{
			RenderServiceSoap renderService  = new RenderServiceSoap();
			Pushpin[] pushpins = new Pushpin[1];
			MapSpecification mapSpec  = new MapSpecification();

			renderService.Credentials = new System.Net.NetworkCredential(myUserName,myPassword);
			renderService.PreAuthenticate = true;
				
			pushpins[0] = new Pushpin();
			pushpins[0].IconDataSource = "MapPoint.Icons";
			pushpins[0].IconName = "0";
			pushpins[0].Label = foundAddressResults.Results[0].FoundLocation.Entity.Name;
			pushpins[0].LatLong = views[0].CenterPoint;
			pushpins[0].ReturnsHotArea = true;

			mapSpec.DataSourceName = "MapPoint.EU";
			mapSpec.Views = views;	
			mapSpec.Pushpins = pushpins;
			mapSpec.Options = new MapOptions();				
			mapSpec.Options.Format = new ImageFormat();
			mapSpec.Options.Format.Width = pbMap.Width;
			mapSpec.Options.Format.Height = pbMap.Height;

			MapImage[] mapImages = renderService.GetMap(mapSpec);	
			System.IO.Stream streamImage = new System.IO.MemoryStream(mapImages[0].MimeData.Bits);
			Bitmap bitmapImage = new Bitmap(streamImage);
			pbMap.Image= bitmapImage;			
		}

		private void btnFind_Click(object sender, System.EventArgs e)
		{
			try
			{
				MakeAddress();
				MakeMap();
				tcMap.SelectedIndex=1;
			}
			catch (System.Web.Services.Protocols.SoapException ex)
			{
				MessageBox.Show(ex.Message.ToString());
			}

		}

		private void btnZoomIn_Click(object sender, System.EventArgs e)
		{
			views[0].Height = views[0].Height/2;
			views[0].Width = views[0].Width /2;
			MakeMap();
		}

		private void btnZoomOut_Click(object sender, System.EventArgs e)
		{
			views[0].Height = views[0].Height * 2;
			views[0].Width = views[0].Width * 2;
			MakeMap();
		}

		private void btnRoute_Click(object sender, System.EventArgs e)
		{
			try
			{
				latlongs = new LatLong[2];
				FindStartAddress();
				FindEndAddress();	
				MakeRoute();
				tcMap.SelectedIndex=3;
			}
			catch (System.Web.Services.Protocols.SoapException ex)
			{
				MessageBox.Show(ex.Message.ToString());
			}
		}

		private void FindStartAddress()
		{
			FindServiceSoap findService = new FindServiceSoap();
			Address myAddress =  new Address();
			FindAddressSpecification findAddressSpec = new FindAddressSpecification();
			FindResults startResult;

			//
			findService.Credentials= new System.Net.NetworkCredential(myUserName,myPassword);
			findService.PreAuthenticate = true;

			//
			myAddress.AddressLine = txtStartAddress.Text;		
			myAddress.PrimaryCity = txtStartCity.Text;
			myAddress.PostalCode = txtStartPostCode.Text;
			myAddress.CountryRegion = "UK";
		
			//
			findAddressSpec.DataSourceName = "MapPoint.EU";
			findAddressSpec.InputAddress = myAddress;	
			
			//
			startResult = findService.FindAddress(findAddressSpec);
			latlongs[0] = new LatLong();
			latlongs[0] = startResult.Results[0].FoundLocation.LatLong;
		}

		private void FindEndAddress()
		{
			FindServiceSoap findService = new FindServiceSoap();
			Address myAddress =  new Address();
			FindAddressSpecification findAddressSpec = new FindAddressSpecification();
			FindResults endResult;

			//
			findService.Credentials= new System.Net.NetworkCredential(myUserName,myPassword);
			findService.PreAuthenticate = true;

			//
			myAddress.AddressLine = txtEndAddress.Text;		
			myAddress.PrimaryCity = txtEndCity.Text;
			myAddress.PostalCode = txtEndPostCode.Text;
			myAddress.CountryRegion = "UK";
		
			//
			findAddressSpec.DataSourceName = "MapPoint.EU";
			findAddressSpec.InputAddress = myAddress;	
			
			//
			endResult = findService.FindAddress(findAddressSpec);
			latlongs[1] = new LatLong();
			latlongs[1] = endResult.Results[0].FoundLocation.LatLong;
		}

		private void MakeRoute()
		{
			RouteServiceSoap routeService = new RouteServiceSoap();
			MapOptions options = new MapOptions();
			Route route;
			
			options.Format = new ImageFormat();
			options.Format.Height = pbMap.Height;
			options.Format.Width = pbMap.Width;
	
			routeService.Credentials= new System.Net.NetworkCredential(myUserName,myPassword);
			routeService.PreAuthenticate = true;

			route = routeService.CalculateSimpleRoute(latlongs,"MapPoint.EU",SegmentPreference.Quickest);
			
			int nMaps = route.Itinerary.Segments[0].Directions.Length + 1;		

			//ViewByBoundingRectangle[] views = new ViewByBoundingRectangle[nMaps];
			views = new ViewByHeightWidth[nMaps];

			m_Maps = new Bitmap[nMaps];

			//Set blank pushpins for each map due to a bug in the compact framework
			Pushpin[] pushpins = new Pushpin[nMaps];
			for (int lcv = 0; lcv < nMaps - 1; lcv++)
			{
				//views[lcv] = route.Itinerary.Segments[0].Directions[lcv].View.ByBoundingRectangle;
				views[lcv] = route.Itinerary.Segments[0].Directions[lcv].View.ByHeightWidth;
				pushpins[lcv] = new Pushpin();
				pushpins[lcv].IconDataSource = "MapPoint.Icons";
				pushpins[lcv].IconName = "0";
				pushpins[lcv].LatLong = route.Itinerary.Segments[0].Directions[lcv].LatLong;
				pushpins[lcv].ReturnsHotArea = true;
			}
			//views[nMaps - 1] = route.Itinerary.Segments[1].Directions[0].View.ByBoundingRectangle;
			views[nMaps - 1] = route.Itinerary.Segments[1].Directions[0].View.ByHeightWidth;
			pushpins[nMaps - 1] = new Pushpin();
			pushpins[nMaps - 1].IconDataSource = "MapPoint.Icons";
			pushpins[nMaps - 1].IconName = "1";
			pushpins[nMaps - 1].LatLong = route.Itinerary.Segments[1].Directions[0].LatLong;
			pushpins[nMaps - 1].ReturnsHotArea = true;

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

			MapImage[] images;
			RenderServiceSoap renderService  = new RenderServiceSoap();
			renderService.Credentials = new System.Net.NetworkCredential(myUserName,myPassword);
			renderService.PreAuthenticate=true;		
			images = renderService.GetMap(myMapSpec);
				
			for (int lcv = 0; lcv < nMaps; lcv++)
			{
				m_Maps[lcv] = new Bitmap(new System.IO.MemoryStream(images[lcv].MimeData.Bits));
			}

			pbRouteMap.Image = m_Maps[0];
			Position = 0;
		}

		private void btnMoveNext_Click(object sender, System.EventArgs e)
		{
			Position += 1;
			pbRouteMap.Image = m_Maps[Position];
		}

		private void btnMovePrevious_Click(object sender, System.EventArgs e)
		{
			Position -= 1;
			pbRouteMap.Image = m_Maps[Position];
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -