Legal | Privacy
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:

Overview
Prerequisites
Creating a Regular J2EE Application
Configuring Oracle Application Server for Location Based Services
Adding Location Based Capability to the J2EE Application
Summary
Related Information

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.

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.

 

Prerequisites

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

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.

Move your mouse over this icon to see the image


2.

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

Move your mouse over this icon to see the image

Observe that a project named Project is created.

Move your mouse over this icon to see the image

 

3.

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

Move your mouse over this icon to see the image

 

4.

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

Move your mouse over this icon to see the image

 

5.

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

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

 

6.

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

Move your mouse over this icon to see the image

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>

Move your mouse over this icon to see the image

 

7.

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

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

Move your mouse over this icon to see the image

 

 

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.

Move your mouse over this icon to see the image

 

2.

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

Move your mouse over this icon to see the image

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

Move your mouse over this icon to see the image

 

3.

Click the Site Administration tab.

Move your mouse over this icon to see the image

 

4.

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

Move your mouse over this icon to see the image

 

5.

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

Move your mouse over this icon to see the image

 

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;

Move your mouse over this icon to see the image

 

7.

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

Move your mouse over this icon to see the image

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

Move your mouse over this icon to see the image

 

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;

Move your mouse over this icon to see the image

 

9.

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

Move your mouse over this icon to see the image

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

Move your mouse over this icon to see the image

 

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;

Move your mouse over this icon to see the image

 

11.

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

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

Click Yes when prompted for confirmation.

Move your mouse over this icon to see the image

Move your mouse over this icon to see the image

Move your mouse over this icon to see the image

 

 

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.

Move your mouse over this icon to see the image

 

2.

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

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

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"%>

Move your mouse over this icon to see the image

Move your mouse over this icon to see the image

 

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
%>

Move your mouse over this icon to see the image

 

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>

Move your mouse over this icon to see the image

 

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

Move your mouse over this icon to see the image

 

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%>>

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

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]%>"><%
%>

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

 

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.

 

 

 

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy