Adding Location Based Services to Your Application
Adding Location Based Services to Your Application
This tutorial describes how to add location-based services
to a regular J2EE application.
Approximately 45 minutes
This tutorial covers the following topics:
Place the cursor over this icon to load and view all
the screenshots for this tutorial. (Caution: Because this action loads all screenshots
simultaneously, response time may be slow depending on your Internet connection.)
Note:
Alternatively, you can place the
cursor over each individual icon in the following steps to load and view only
the screenshot associated with that step.
Back to Topic List
|
The OracleAS Wireless Location Based Services (LBS)
platform provides a simple, integrated solution to enhance applications
with LBS capabilities. Using the OracleAS Wireless LBS capability, you
can add maps, driving directions, and information from Yellow Pages to your applications.
|
Back to Topic List
Before starting this tutorial, you should:
| 1. |
Have installed Oracle JDeveloper 10g (Version 9.0.5.1)
|
| 2. |
Have installed Oracle Application
Server 10g Infrastructure |
| 3. |
Have installed Oracle Application
Server 10g Portal and Wireless |
Back to Topic List
You can create a regular J2EE application and then add Location
Based functionality to it. To create a simple J2EE application, perform the
following steps:
| 1. |
Start JDeveloper. In Applications - Navigator, right-click Applications, and select New Application Workspace from the shortcut menu.

|
| 2. |
Change the Application Name to LBSApps in the Create Application
Workspace dialog box. Observe that the Directory Name also changes.
Click OK.

Observe that a project named Project is created.

|
| 3. |
Right-click the project in System-Navigator and select New
from the context menu. In New Gallery, expand Web Tier under
Categories.

|
| 4. |
Select JavaServer Pages (JSP) from Categories and then select
JSP Page from Items. Click OK.

|
| 5. |
Enter MapAndRoute.jsp in the File Name field, and click OK.

You see the Design view and Source view of MapAndRoute.jsp.
You also see the component palette, data controls, and property inspector
on the right. Optionally, you can close the component palette
and property inspector.

|
| 6. |
Click the Source tab to see the source code for MapAndRoute.jsp.

Copy and paste the following code to the code editor window to replace
the existing code:
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>Welcome!!</title>
</head>
<body>
<% String user = request.getParameter("user"); %>
<H3>Welcome
<%= (user==null) ? "" : user %>
</H3>You have requested for today's date!
<P>
<B>Today is
<%= new java.util.Date() %>. Have a great day!!
</B>
</P>
<B>Please enter your name:</B>
<form method="get">
<input type="text" name="user" size="15"/>
<input type="submit" value="Submit Name"/>
</form>
</body>
</html>

|
| 7. |
Right-click MapAndRoute.jsp, and select Run to run the
JSP file.

|
| 8. |
You see the application running on the default browser. Enter your
name in the text field below the text, "Please enter your name."
Click Submit Name to view the results.

|
Back to Topic List
|
Before you can use the LBS functionality from your applications,
you need to configure content providers on Oracle Application Server.
This section describes how to configure the eLocation geocoding, mapping,
and routing content providers. To configure Oracle Application Server
for Location Based Services, perform the following steps:
|
| 1. |
Open your browser, and enter the following URL:
http://<hostname>.<domain>:<em_port>
Note: The administration port number is automatically assigned
during server installation and may be different for your installation.
When prompted for username and password, enter ias_admin and the
password that you entered during installation.

|
| 2. |
In Enterprise Manager 10g Application Server Control, click
the name of your middle tier instance to see the instance home page.

Scroll down to go to the System Components table, and click the Wireless link.

|
| 3. |
Click the Site Administration tab.

|
| 4. |
Expand Component Configuration and click Location Services
under Location-Related.

|
| 5. |
The Location Services page is displayed. Go to the Location Service Configurations
section, and click
Geocoding Configuration.

|
| 6. |
In order for your applications to support the LBS geocoding functionality,
a geocoding provider needs to be configured. Here we configure Oracle
eLocation. Note that Oracle eLocation can only be used for testing and
demonstration purposes. Click Add Another Row to create a new blank row
for your geocoding provider. Enter the following information, and click
Apply. Please note that the new configuration will not take effect
until you restart your Wireless server. We will do this after configuring
all providers.
Provider Name: eLocation
Preference: 1 Provider Implementation Class Name: oracle.panama.spatial.core. geocoder.GeocoderImplXMLProvider
URL: http://elocation.oracle.com/elocation/lbs
Username: usr
Password: pwd
ISO Locales: ;US;unknown;

|
| 7. |
Navigate back to the Location Services page by clicking Location Services
in the breadcrumbs.

Go to the Location Service Configurations table, and click Mapper
Provider Configuration.

|
| 8. |
In order for your applications to support the LBS mapping functionality,
a mapping provider needs to be configured. Here we configure Oracle
eLocation. Note that Oracle eLocation can only be used for testing and
demonstration purposes. Click Add Another Row to create a new blank row
for your mapping provider. Enter the following information, and click Apply.
Please note that the new configuration will not take effect until you
restart your Wireless server. We will do this after configuring all providers.
Provider Name: eLocation
Preference: 1
Provider Implementation Class Name: oracle.panama.spatial.core.mapper. MapperImplXMLProvider
URL: http://elocation.oracle.com/elocation/lbs
Username: usr
Password: pwd
Parameters: us_base
ISO Locales: ;US;unknown;

|
| 9. |
Navigate back to the Location Services page by clicking Location Services
in the breadcrumbs.

Go to the Location Service Configurations table, and click Routing
Configuration

|
| 10. |
In order for your applications to support the LBS routing functionality,
a routing provider needs to be configured. Here we configure Oracle
eLocation. Note that Oracle eLocation can only be used for testing and
demonstration purposes. Click Add Another Row to create a new blank row
for your routing provider. Enter the following information, and click Apply.
Please note that the new configuration will not take effect until you
restart your Wireless server. We will do this after configuring all providers.
Provider Name: eLocation
Preference: 1
Provider Implementation Class Names: oracle.panama.spatial.core.router .RouterImplXMLProvider
URL: http://elocation.oracle.com/elocation/lbs
Username: usr
Password: pwd
Parameters: us_base
ISO Locales: ;US;unknown;

|
| 11. |
Navigate back to the Enterprise Manager 10g Application Server Control
main page by clicking the instance in the breadcrumbs.

Restart the Wireless server so that your configuration changes take
effect. In the System Components table, select the Wireless
component check box, and click Restart.

Click Yes when prompted for confirmation.



|
Back to Topic List
To add Location Based Capability to your J2EE application,
perform the following steps:
| 1. |
First, we need to set up the library path in JDeveloper to include the
classes used by LBS. Right-click your JDeveloper project and select
Project Properties.

|
| 2. |
Click Libraries under Development in the right frame and click
New to add a new library for LBS.

|
| 3. |
Enter Wireless for Library Name. Set the classpath to include
the wireless.jar from your installation. For example, C:\midtier_pw\wireless\lib\wireless.jar.
Click OK.

The new library should now appear in your Selected Libraries list.
Click OK to close the Properties window.
|
| 4. |
Add the following lines directly following the contentType declaration
in your MapAndRoute.jsp. Remove all content between the <body>
tags for clarity. Make sure that MapAndRoute.jsp compiles successfully by right-clicking the file name and selecting Make.
<%@ page import="oracle.panama.spatial.SpatialManager"%>
<%@ page import="oracle.panama.model.Location"%>
<%@ page import="oracle.panama.spatial.geocoder.Geocoder"%>
<%@ page import="oracle.panama.spatial.mapper.Mapper"%>
<%@ page import="oracle.panama.imagex.ImageFormats"%>
<%@ page import="oracle.panama.spatial.router.Router"%>
<%@ page import="oracle.panama.spatial.router.RoutingResult"%>
<%@ page import="oracle.panama.spatial.router.RoutingOption"%>
<%@ page import="oracle.panama.spatial.router.RoutingSettings"%>
<%@ page import="java.util.Locale"%>


|
| 5. |
In this example, we create two locations and then geocode them,
show them on a map, and find the optimal route between them. Let's start
by defining our starting and ending locations. Insert the following lines
between the body tags.
<%
// Create the source location object
Location fromLoc = SpatialManager.createLocation(
null, //point
"OracleHQ", //companyName
"", //houseNumber
new String[] { "500 Oracle Parkway" }, //intersectingStreetNames
null, //secondLine
"Redwood City", //cityName
"CA", //stateName
"94065", //postalCode
null, //postalCodeExt
"US"); //countryName
// Create the destination location object
Location toLoc = SpatialManager.createLocation(
null, //point
"Hotel", //companyName
"", //houseNumber
new String[] { "3000 Los Prados St" }, //intersectingStreetNames
null, //secondLine
"San Mateo", //cityName
"CA", //stateName
"9440", //postalCode
null, //postalCodeExt
"US"); //countryName
%>

|
| 6. |
Now, lets test the geocoder. Insert the following lines directly after
the address declaration.
<%
// Get the geocoder
Geocoder geocoder = SpatialManager.getGeocoder();
// Geocode the locations
Location[] geocodedStart = geocoder.geocodeAddress(fromLoc,Geocoder.MATCH_MODE_TIGHT);
Location[] geocodedEnd = geocoder.geocodeAddress(toLoc,Geocoder.MATCH_MODE_TIGHT);
%>
You are located at:<br>
Latitude: <%=(double)Math.round(geocodedStart[0].getLatitude()*1000) / 1000%><br>
Longitude: <%=(double)Math.round(geocodedStart[0].getLongitude()*1000) / 1000%></h2>
You want to get to:<br>
Latitude: <%=(double)Math.round(geocodedEnd[0].getLatitude()*1000) / 1000%><br>
Longitude: <%=(double)Math.round(geocodedEnd[0].getLongitude() * 1000) / 1000%></h2>

|
| 7. |
Compile the code. For quick deployment, copy and paste MapAndRoute.jsp
in the following folder:
<midtier_home>\j2ee\OC4J_Wireless\applications\wireless\location-web
Access the application with the
URL http://<hostname>.<domain>:<HTTP_Port>/location/MapAndRoute.jsp

|
| 8. |
Now lets test the mapper. Insert the following lines directly after the
geocoder test.
<%
// Get the mapper
Mapper mapper = SpatialManager.getMapper();
// Get the map URLs
String startMapURL = mapper.getMapURL(fromLoc, ImageFormats.GIF, 400, 200, false);
String endMapURL = mapper.getMapURL(toLoc, ImageFormats.GIF, 400, 200, false);
%>
Here is your start location:<br>
<img src=<%=startMapURL%>><br><br>
Here is your destination location:<br>
<img src=<%=endMapURL%>>

|
| 9. |
Compile the code. Copy and paste the modified MapAndRoute.jsp
in the following folder:
<midtier_home>\j2ee\OC4J_Wireless\applications\wireless\location-web
Refresh the application browser window that was used in step 7. The eLocation-mapping provider has generated maps of the given addresses.

|
| 10. |
Now, let us test the router. Insert the following lines at the end of
your mapper test.
<%
// Get the router
Router router = SpatialManager.getRouter();
// Basic routing settings: return mapURL, don't return route geometry
RoutingSettings settings = new RoutingSettings(true, false);
settings.setSecondaryOption(RoutingOption.overviewMapWidth, "500");
settings.setSecondaryOption(RoutingOption.overviewMapHeight, "300");
// Compute the route
RoutingResult rres = router.computeRoute(fromLoc, toLoc, null, settings, Locale.US);
%><br><br><br>Here are your driving directions:</br><%
for (int i=0; i<rres.getManeuvers().length; i++)
{
%><%=rres.getManeuvers()[i].getNarrative()%><br><%
}
%><br><img src="<%=rres.getOverviewMapURL()[0]%>"><%
%>

|
| 11. |
Compile the code. Copy and paste the modified MapAndRoute.jsp
in the following folder:
<midtier_home>\j2ee\OC4J_Wireless\applications\wireless\location-web
Refresh the application browser window. The eLocation routing provider
has generated driving directions and an overview map of the requested
route. Click here to get the entire
LBS example.

|
Back to Topic List
|
Create a simple JSP page using JDeveloper
|
|
Configure Oracle Application Server for Location Based
Services
|
|
Modify the JSP page to add the following Location Based
capability:
Create source and destination locations
Geocode the locations
Show maps for the locations
Show the driving directions to the destination
|
 |
Deploy the application (JSP) to the application server |
 |
Run the application to test Location Based Services |
 |
To ask a question about this OBE tutorial, post a query on the OBE
Discussion Forum |
Place the cursor over this icon to hide all screenshots.
Copyright © 2004 Oracle Corporation. All Rights Reserved.
|