Windows Mobile: applications that use GPS and website maps for location sensing

Source: Internet
Author: User
We show you how to build a location awareness task list application for a windows mobile device that uses GPS to send you a task reminder at the appropriate time and location.

Download the sample source code or material in this article

This article uses the following technologies:

Windows Mobile 6, mappoint

This article introduces the following:

Mappoint Web Service

Cache tasks and maps

Obtain the required neighboring points.

Create a task

Directory

Use mappoint for locating

Task and pocket Outlook

Application Architecture

Obtain neighboring points

Add task

All The Way Forward

Recently, I have moved to my new home. Some of my friends spent a whole day packing and unpacking, placing items, and processing other boring but forced relocation jobs. On the way back to the old house to fetch the last box, I almost forgot to prepare dinner for them. I set up a reminder on my windows mobile phone, but it cannot tell me when I drive through the most convenient external store.

I hope that the phone will notify me when I reach the desired target. If we can get a reminder at the right time and place, we can enjoy ourselves after a hard day, instead of driving back and forth in a strange location.

Windows Mobile provides many interfaces and functions that help devices understand their environments-location, signal, and semaphore. But how can we use these features for your applications? Among these features, Location Awareness is the most prominent and useful. You can create various Location Awareness applications, from the purpose-specific satellite navigation program to the more complex task list discussed in this article.

This article mainly introduces the problems involved in using this function, as well as other code that needs to be written for developing useful applications. In this article, I will discuss the mobile application development environment and utilities, and show you how to build a location-aware task list application that reminds you of the appropriate time and location.

Use mappoint for locating
The my location awareness task list application (wheretodo) needs to execute several core tasks. It needs to obtain the geographic location information of the phone. You also need to store and monitor tasks. In addition, applications also need to know which stores and services are available near the current location of the phone, which can be used to solve the current task. At last, it needs to receive a call. Application Interface 1.

Figure 1 wheretodo Application

Applications require geographic data first. Considering the purpose of this article, I chose to use the Microsoft mappoint web service. This Web Service is a basic technology for Live Search maps and Virtual Earth, providing nearby search services for Europe and the United States. The provided sample code uses the European map data settings. You need to change the settings based on the work location.

Mappoint uses the search code of the GPS dimension, longitude, and specific storage type as its parameter. The fakegps utility installed on a simulator or smartphone provides location information. (For more information about this utility, see the "fakegps" column .)

Mappoint provides soap APIs for XML Web Services. Web services are divided into four main services: public services, search services, rendering services, and route services. This application is most concerned with the search service, but if you want to guide the user or map direction, you can also use other services to expand functions.

A public service (commonservicesoap) contains the common classes, methods, and attributes of the search service, route service, and rendering service, or basic utility functions.

You can use the search service (findservicesoap) to locate the address, geographical entity, dimension, and longitude coordinates, and the point of interest (POI) of mappoint Web Service data ). You can also parse the address and return location information for the specified dimension and longitude.

You can use render service (renderservicesoap) draw a roadmap and location map, place a map pin, draw a polygon area, set the map size and map view, select a point on the map, obtain the location information of the relevant points and polygon on the map, and translate and zoom the map..
Routeservicesoap can generate routes, travel directions, route representations calculated based on locations or road signs (used to present highlighted routes on a map) set road sections and preferred routes, and generate map views of road sections and directions.

There is a complete set of Object Model class diagrams on msdn. Mappoint stores data used to search for services, route services, and rendering services in multiple data sources based on the geographical region or required information type. You can find all the mappoint technical articles on service use in the msdn magazine.

Task and pocket Outlook

The pocket outlook Object Model (poom) allows you to add menus and functions to the "tasks" and "contacts" applications of Windows Mobile and to process their associated items and data. The Location Awareness application has three main interfaces: iappointment, itask, and icontact.

Iappointment represents an appointment in the calendar ar folder. A single appointment object can represent a meeting, a appointment, or a scheduled appointment or meeting.

Itask indicates an assigned, delegated, or self-assigned task to be completed within the specified time range. Task items are included in the Tasks folder.

Icontact indicates the contact in the contacts folder. You can use this method to save, delete, copy, or display contacts. The ipoutlookitemcollection interface can be used to add new contacts or retrieve existing contacts.

The example application uses itask. (In terms of functionality, iappointmen can be used, but this interface is not suitable for the direct needs of applications .) Poom is similar to the desktop outlook object model. You can learn more about the difference between the pocket outlook object model and the outlook Object Model on msdn.

Application Architecture

A Location Awareness application consists of two function chains. The first is to monitor the current task and problem system, as shown in figure 2. Tasks are stored in the SQL servercompact database table. In addition, a group of auxiliary data is stored in another table named geocache. Use a separate table to limit the number of connections required. I will introduce it later in this article.

Figure 2 monitor location-aware tasks and issue alerts

The Microsoft mappoint Web Service provides information about neighboring points. Mappoint web services in different regions in the world have different data sources and their functions are different. The data source used by the sample application is navtech. eu. After this information is collected, you can perform distance calculations and issue alerts (if applicable ).

The second is the event chain (see figure 3). You can use poom to add tasks to the task list on a Windows mobile device. The framework also allows access to calendar and SMS functions.

Figure 3 system flow used to add tasks to the wheretodo Application

"Tasks and cache" (task and cache) represents the first part of the event monitoring and alarm chain. The task manager only needs to obtain a task list from poom. It can also manage geocache to solve problems that occur when devices with limited connection use web devices. Device connections are classified into permanent connections, occasional connections, or no connections at all.

To adapt to multiple connection situations, you need an appropriate web service data cache policy and a simple system that understands how to make full use of the connection. Although we can easily imagine a very complex situation, we have formulated a simple radius buffer policy in this article. For example, a query is sent to the mappoint web service to search all Chinese food outlets within a given radius (for example, 80 kilometers (km. After you go 40 km in any direction, a new search is generated. It follows the principle that the cost of sending each query to the Web Service is very high.
It also assumes that the distance from the input point of the task is unlikely to exceed 40 km. Since the distance used to control the buffer operation may vary with people and countries, it is designed for user input.

Logs that query the running locations are stored in the geocachelog database. This log is checked before any other query is executed to prevent duplicate information from Web Service requests. It also provides an opportunity to use a large amount of information to pre-fill the system.

Fakegps

Fakegps Application

The Windows Mobile 6 SDK contains a utility named fakegps that allows you to test applications using simulated GPS data. For information on using fakegps for installation and testing, see the msdn library article "using fakegps utility ".

Fakegps reads a set of pre-recorded GPS commands. GPS data can be obtained from real GPS devices using the original GPS data recorder. The fakegps device reads the generated file and re-runs the file to simulate changing the location data for testing. For example, I recorded a trip to London to collect data for my application and re-planned the journey through fakegps.

Obtain neighboring points

The next component defines how to fill in geocache. When an application needs to find a location, the getnearbypoi function is called (see figure 4 ). The Code queries the mappoint web service. Note that the code displayed here is simplified for clarity, which is different from the code downloaded.

Figure 4 obtain the desired neighboring point

private void GetNearByPOI(
 string KeyWord, LatLong CurrentPosition) {
 FindServiceSoap findService = new FindServiceSoap();
 FindNearbySpecification findNearBySpec = new FindNearbySpecification();
 findService.Credentials =
  new System.Net.NetworkCredential(myUserName, myPassword);
 findService.PreAuthenticate = true;
 findNearBySpec.Distance = Convert.ToDouble(inputdistance.Text);
 findNearBySpec.LatLong = new LatLong();
 findNearBySpec.LatLong.Latitude = CurrentPosition.Latitude;
 findNearBySpec.LatLong.Longitude = CurrentPosition.Longitude;
 findNearBySpec.Filter = new FindFilter();
 //findNearBySpec.Filter.EntityTypeName = KeyWord;
 findNearBySpec.Filter.EntityTypeName = "FoodType3"; // SIC CODE
 findNearBySpec.DataSourceName = "NavTech.EU";
 FindResults foundResults;
 foundResults = findService.FindNearby(findNearBySpec);
 string connectionString;
 string fileName = System.IO.Path.GetDirectoryName(
  System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) +
  "wheretodo.sdf";
 string password = "sa";
 connectionString = string.Format("DataSource="{0}"; Password='{1}'",
  fileName, password);
 SqlCeConnection cn = new SqlCeConnection(connectionString);
 cn.Open();
 SqlCeCommand cmd;
 //Loop Round and add it to the geocache
 foreach (FindResult fr in foundResults.Results) {
  //This needs to include LongLat in geocache
  string sql =
   "insert into geocache2 (POI_Name, POI_Address, POI_Tel, POI_Web, " +
   "POI_POST_ZIP, POI_Lat, POI_Long, POI_KeyWord) " +
   "values (@Name, @Address, @Tel, @Web, @POST_ZIP, '" +
   fr.FoundLocation.LatLong.Latitude.ToString() +
   "', '" + fr.FoundLocation.LatLong.Longitude.ToString() + "', '" +
   KeyWord.ToString() + "')";
  cmd = new SqlCeCommand(sql, cn);
  cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 255, "Name").Value =
   fr.FoundLocation.Entity.Properties[0].Value.ToString();
  cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 255, "Address").Value =
   fr.FoundLocation.Entity.Properties[1].Value.ToString() +
   fr.FoundLocation.Entity.Properties[2].Value.ToString();
  cmd.Parameters.Add("@Tel", SqlDbType.NVarChar, 255, "Tel").Value =
   fr.FoundLocation.Entity.Properties[9].Value.ToString();
  cmd.Parameters.Add("@Web", SqlDbType.NVarChar, 255, "Web").Value =
   "http://m.live.com";
  cmd.Parameters.Add("@POST_ZIP", SqlDbType.NVarChar, 255, "POST_ZIP").Value =
   fr.FoundLocation.Entity.Properties[7].Value.ToString();
  cmd.ExecuteNonQuery();
  //Update geocachelog
  sql = "insert into GeoCodeLog (Keyword, Lat, Long ) values ('" + KeyWord +
   "', '" + fr.FoundLocation.LatLong.Latitude.ToString() + "', '" +
   fr.FoundLocation.LatLong.Longitude.ToString() + "' )";
  cmd = new SqlCeCommand(sql, cn);
  cmd.ExecuteNonQuery();
 }
}

See the code snippet that calls currentposition. Latitude and currentposition. longpolling. It is derived from the GPS intermediate driver, a software layer between the application and the driver of the GPS hardware device. This abstraction layer allows you to write an application at a time and use it with multiple GPS devices. The GPS intermediate driver API is made public through the local code library. You can use the example that comes with the Windows Mobile 6 Professional SDK to obtain the permission to access the library from the managed code (see "using GPS intermediate driver through managed code )".
Now you have the current location and POI in the vicinity related to the task, where they are created by navtech. the Standard Industrial Classification code (sic) used in the EU data source, you need to accurately determine the distance between these points and your current location. I use the longitude and dimension values returned from the web service and GPS (fakegps in this example); Figure 5 shows how to convert these values to distances.

Figure 5 Distance Calculation

private double GetLatLongTuppleDistance(
 double Lat1, double Long1, double Lat2, double Long2) {
 //Convert Degress to Radians for Calculations
 double Lat1r = ConvertDegreesToRadians(Lat1);
 double Lat2r = ConvertDegreesToRadians(Lat2);
 double Long1r = ConvertDegreesToRadians(Long1);
 double Long2r = ConvertDegreesToRadians(Long2);
 // Spherical law of cosines formula—ignores the effect of hills
 double R = 6371; // Earth's radius (km)
 double d = Math.Acos(Math.Sin(Lat1r) * Math.Sin(Lat2r) +
  Math.Cos(Lat1r) * Math.Cos(Lat2r) *
  Math.Cos(Long2r—Long1r)) * R;
 //Returns distances in km
 return d;
}

The spherical trigonometric function based on the cosine law of the sphere (which can deduce the hook theorem) provides a function that converts a dimension and a longitude to a distance (Unit km. To calculate the distance between you and the location you are looking for, there are many complex factors involved, and the above functions clearly make assumptions about these factors. Because the earth is not a standard sphere, there will be errors when using these formulas. 1 mile on land = 1.609344 kilometers, and 1 nautical mile on SEA = 1.852 kilometers.
The last part of the event chain is to send an alarm to the user when finding a task solution within a certain distance from the current location. This distance depends on the transportation mode (driving, walking, cycling, etc.), so it is left for users to enter.

Add task

Of course, you must add a task to the mobile device before the application can find the location. Poom mirrors the outlook object model, but in order to adapt to the actual situation of mobile devices, it reduces its functional scope.

With poom, you can easily modify and display appointment, task, and contact items, and manipulate folders containing the content. The code for creating a task item is as follows:

OutlookSession outlooksession = new OutlookSession();
Task NewTask = new Task();
NewTask.Body = textBox2.Text.ToString();
string MyString = dateTimePicker2.Value.ToShortDateString() + " " + dateTimePicker1.Text.ToString();
DateTime MyDateTime = new DateTime();
MyDateTime = DateTime.ParseExact(MyString, "M/d/yy h:mm:ss tt", null);
NewTask.DueDate = MyDateTime.ToUniversalTime();
NewTask.Subject = textBox1.Text.ToString();
outlooksession.Tasks.Items.Add(NewTask);

You can change various parameters to set the end date and task body, and then add it to poom.

This component is the last of the two component chains used to provide the wheretodo application function. The system UI is very simple. It can be used to set all relevant information and determine the SIC code that the application will find. The whole application is encapsulated into an infinite loop. Its function is to explain how to use Location Awareness applications. You can easily add it as a background service to a mobile device so that it can be integrated into a Windows Mobile 6 or Windows Mobile 5 environment more efficiently and concisely.

Mobile Data Resources

Data point: access data from mobile applications

 

All The Way Forward

You have seen a location aware device that can easily develop these applications. This basic concept allows you to easily expand the Location Awareness task list for RFID.

Improvements to this Code can be applied to any location-aware application. The above content can be attributed to the close connection between Location Awareness and other context awareness services running on most mobile phones. In addition to your location, the task knows nothing about the other things you want to try. You can set the time and position for the task so that they can be triggered when a specific time (for example, driving home after work) approaches a certain position. Even better, the task reminder will know that you will have a meeting in 10 minutes, and even if you will pass the post office on the way to the meeting, there is not enough time to buy stamps.

Http://tech.ddvip.com/2009-02/1233823276107398.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.