How to Perform Geo-Location on BREW-based Phones

How to Perform Geo-Location on BREW-based Phones

In this application, we will show you how you should be able to use the GPSOne features built into the BREW SDK to perform geo-location on BREW-based phones… once BREW phones featuring GPS hardware are commonly available on the market. We will combine this understanding with the powers of Microsoft’s MapPoint .NET Web Services to automatically generate maps of the area surrounding your simulated BREW-based device.

Gathering the .NET Server Pieces

Software Needed
In order to create the .NET portion of the code, you will need three things. The first of these is Internet Information Server, the second is Visual Studio .NET 2003, and the third-and-final thing is the MapPoint .NET Developer Web Services SDK.
Read on….

Building the .NET BREW Server
Technically, you could write a BREW client that talks directly to Microsoft’s MapPoint.NET Web Services using XML. However, there are at least two good reasons why building a custom .NET Web Application to “sit in the middle” and mediate such conversations is a good idea.

At one level, there are no direct XML processing interfaces available in the default BREW SDK (although Qualcomm does have an XML Extension available), much less SOAP libraries. So, talking directly from BREW to MapPoint .NET would be tedious at best.

Even more importantly, MapPoint.NET currently only returns GIF images for maps. GIF formatted images are not supported by many BREW devices. Our custom .NET Web Application, then, will be responsible for translating into the PNG format, which is supported by many more BREW devices.

Before we begin, we will need to create some temporary space for storing MapPoint .NET maps on our server while they are being worked on. In order to do this, create a folder named “brew” on your C: drive and make sure to give read/write access on it to “Everyone.”

In Visual Studio .NET 2003, choose to create a new ASP.NET Web Application project named “BREWServer”. Once this has finished being created, right click “References” in the Solution Explorer and choose “Add Web Reference…” Fill in the URL field as shown in Figure 1, then click “Go.” Change the “Web Reference Name” to MapPointService then click “Add Reference.”

Once you have returned to the standard Forms Designer view, right click the “WebForm1.aspx” icon in the Solution Explorer and choose “View Code.” Change the namespace imports at the top of the code to match Listing 1. Also, inside the Page_Load event, replace the existing comment with the contents of Listing 2. Note, however, that the bolded ID and PASSWORD references in line 2 should be replaced with the ID and password taken from your MapPoint email discussed above.

If you now Build your solution from the Visual Studio “Build” menu, you should find that it all compiles without error. If you now open Internet Explorer (or the browser of your choice) and go to the following URL:


…you should get a map that is centered on downtown Chicago, just like the one shown in Figure 2. If you receive an error, first verify that you have created a “brew” folder in the correct location, with the permissions described above. Then, verify that you are using the exact ID and password you received in an email earlier.

Building the BREW Client
The client that will allow us to view maps of our surroundings on a BREW device will leverage several interfaces in order to make this happen:

IPosDet?will use the BREW phone’s theoretical GPS hardware to determine the device’s current latitude and longitude
IWeb, IWebResp, and IWebRespInfo?will handle the job of making a web request to our custom .NET application
ISource, IFileMgr, and IFile?will help us to save the map returned by MapPoint .NET to a local file on our BREW phone
IImage and IImageCtl?will display the map on our device

Since we don’t have an actual GPS device to hook into our BREW emulator, we will be simulating one. For some background information on how this will work, you can read “Using the NMEA Logger Utility” in the BREW Utilities Guide. In practical terms, you should simply create a text file named “chicago.bgp” containing only the following lines:


Each of these comma-separated values represents a different piece of information about our current location. Of all these, we are only interested in the fourth through seventh ones. These are, respectively, the latitude and longitude of the location that we wish to simulate.

To create a BREW client for MapPoint .NET, we are going to hi-jack the HelloWorld example included with the BREW SDK. Into this, we will inject large pieces of custom code?and a few bits of the NetDiagnostics example, as well!

To make this happen, you should first use the MIF Editor to edit the HelloWorld example’s MIF file, located in the Examples directory of the SDK. On the General tab of the MIF Editor, you must make sure to give yourself permissions for:

Position Location
Web Access

You can now close the MIF Editor and save your changes. Next, you should open the HelloWorld example project under Visual Studio 6 and open its “helloworld.c” file in the code editor. Now, change it all to match Listing 3. Finally, choose “Build helloworld.dll” from the Visual Studio “Build” menu.

Understanding the code
In order to fully understand the code, let’s quickly walk through what will happen when it is executed?method-by-method.

AEEClsCreateInstance will create an instance of our application and call…
InitAppData, which will create instances of our key interfaces (described above) and set some default options describing the way in which IWeb should function
HelloWorld_HandleEvent fires at this point, and the EVT_APP_START case:
Registers the gpsCallback function to be notified when the GPS components return location information
Calls IPOSDET_GetGPSInfo, to ask the GPS components to tell us our current location
Draws “Please Wait” on the screen
This function does not handle EVT_APP_SUSPEND and EVT_APP_RESUME and is, therefore, really only suitable for use with on the emulator in its present state.
gpsCallback fires as soon as the GPS components return location information. This routine:
Approximates our latitude/longitude from the WGS-84 Ellipsoid information that is returned
Uses these coordinates to build a complete URL for our custom .NET application
Passes this URL to WebAction_Start
WebAction_Start registers WebAction_GotResp as a callback and passes this registration plus the URL for our custom .NET Web Application to…
IWEB_GetResponse, which:
Extracts the map that was returned by our custom .NET Web Application as an ISOURCE interface
Creates a new local file called “map.png”
Registers imgCallback as a callback
imgCallback fires whenever there is map data available to be read from the ISOURCE interface. It…
Puts map data into the “map.png” file
Loads the contents of “map.png” into an IImage interface
Uses the IImageCtl interface to display the map on the screen
HelloWorld_HandleEvent now fires whenever an arrow key is pressed at this point, allowing the IImageCtl interface to display a different portion of the map.

WGS-84 Ellipsoids
Our approach to translating from WGS-84 to latitude and longitude works acceptably for large-scale maps such as the ones being demonstrated here. However, if you wanted to show actual street-level maps, you would need to perform more complicated mathematics, such as the ones shown here. Also, please note that street-level maps are currently only available for North America using MapPoint .NET. Attempts to map other locations will produce larger-scale maps than are requested.

Trying it out
You can start the BREW emulator by selecting Programs –> BREW –> BREW Emulator from the Windows Start menu. Once the emulator starts, it should look like Figure 3. From the “Tools” menu, choose “GPS Emulation.” Select the radio button labeled “File Input,” then use the Ellipses button to browse to the “chicago.bgp” file you created earlier. Once you have selected it, click “OK” to return to the emulator.

If the emulator is still in its default configuration, you should now see a number of icons on the emulator display?corresponding to the multiple examples in the BREW SDK “Examples” folder. If you don’t see your “Hello World App” icon listed, use “Change Applet Dir” on the emulator’s “File” menu to point the emulator back at the SDK’s “Examples” folder.

Once you start your new Hello World application, you should see the words “Please wait.” After a brief pause, you should see the upper left-hand portion of the map from Figure 2, as shown in Figure 4.

You can use the arrow keys to move around the image. This will allow you to see the entire map of your “current location” returned by MapPoint .NET. You have to scroll because MapPoint.NET maps are much bigger than the displays on most BREW phones!

To simulate a different location, simply change the values in “chicago.bgp” to reflect a different latitude and longitude, and then restart the application!

Originally published in the BREW Wireless Resource Center


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist