×
Namespaces

Variants
Actions
(Difference between revisions)

Get location coordinates along route in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Update ArticleMetaData)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix underscores in categories)
Line 1: Line 1:
[[Category:Java ME]][[Category:Location]][[Category:Code Examples]]
+
[[Category:Java ME]][[Category:Location]][[Category:Code Snippet]]
{{ReviewerApproved|timestamp=20090927}} {{ArticleMetaData
+
{{ArticleMetaData <!-- v1.1 -->
|platform=Since S60 3rd Edition, Since Series 40 6th Edition
+
|devices=2710N
+
|keywords=javax.microedition.location.LocationProvider,  javax.microedition.location.Location,  javax.microedition.location.Coordinates.getLatitude,  javax.microedition.location.Coordinates.getLongitude()
+
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|devices= 2710N
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= Since S60 3rd Edition, Since Series 40 6th Edition
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices. -->
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|review-by=[[User:skalogir]]
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|review-timestamp=20111006
+
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
|creationdate=20080528
+
|capabilities= <!-- Capabilities required (e.g. Location, NetworkServices. -->
|author=[[User:vivartpandey]]
+
|keywords= javax.microedition.location.LocationProvider,  javax.microedition.location.Location,  javax.microedition.location.Coordinates.getLatitude,  javax.microedition.location.Coordinates.getLongitude()
 +
|id= <!-- Article Id (Knowledge base articles only) -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= [[User:skalogir]]
 +
|review-timestamp= 20111006
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20080528
 +
|author= [[User:vivartpandey]]
 
}}
 
}}
 
==Overview==
 
==Overview==

Revision as of 09:27, 7 February 2012

Article Metadata
Tested with
Devices(s): 2710N
Compatibility
Platform(s): Since S60 3rd Edition, Since Series 40 6th Edition
Article
Keywords: javax.microedition.location.LocationProvider, javax.microedition.location.Location, javax.microedition.location.Coordinates.getLatitude, javax.microedition.location.Coordinates.getLongitude()
Created: vivartpandey (28 May 2008)
Reviewed: skalogir (06 Oct 2011)
Last edited: hamishwillee (07 Feb 2012)

Overview

This is a simple Midlet that can help you get and display on the phone's screen the coordinates on each of a route's critical turning points, as well as the direction (left or right) towards which you are heading. The idea is to be able to send this information to someone who needs directions when following the same route.

Example Code

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
 
public class LBS extends MIDlet implements CommandListener {
//soft key indication for direction.
Command Right = new Command("RIGHT",Command.ITEM,0);
Command Left = new Command("LEFT",Command.BACK,0);
//first coordinate that is your starting point.
 
String direction="Starting point";
public LBS() {}
Form f=new Form("Waiting...");
public void startApp() {
 
f.append("Start");
f.addCommand(Left);
f.addCommand(Right);
f.setCommandListener(this);
Display.getDisplay(this).setCurrent(f);
 
getCoordinates(f,direction);
 
}
 
private void getCoordinates(Form f,String dir) {
try {
Criteria c=new Criteria();
c.setHorizontalAccuracy(100);
c.setVerticalAccuracy(100);
c.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
LocationProvider lp=LocationProvider.getInstance(c);
Location loc=lp.getLocation(60);
QualifiedCoordinates qc=loc.getQualifiedCoordinates();
f.append(dir);
f.append("Alt: "+qc.getAltitude());
f.append("Lat: "+qc.getLatitude());
f.append("Long: "+qc.getLongitude());
 
} catch(Exception e) {
f.append("Exception: "+e);
}
}
 
public void pauseApp() {}
 
public void destroyApp(boolean destroy) {}
 
public void commandAction(Command c, Displayable s) {
//whenever your press left this will show the cordinates
//of the turning point.with the label of left.
 
if (c == Left) {
 
direction="\nLEFT";
getCoordinates(f,direction);
}
//when ever you press the right this will show the coordinates of
// the turning point for the right.
 
if (c == Right) {
 
direction="\nRIGHT";
getCoordinates(f,direction);
}
}
}
101 page views in the last 30 days.