Posts Tagged ‘gps’
JavaME JSR-179 Example Code : Detect Location via TinyGeocoder
I've completed the JSR-179 Location API code for reverse geocoding in JavaME. This code essentially is an expansion of the previous JSR-179 example that i've posted in the blog before, plus the Reverse-Geocoding feature, thanks to TinyGeocoder service.

What this sample MIDlet does?
It obtain coordinates via the mobile phone JSR-179 Location API and subsequently display the name of the location using TinyGeocoder reverse geocoding service.
-
import javax.microedition.midlet.*;
-
import javax.microedition.lcdui.*;
-
import javax.microedition.location.*;
-
import javax.microedition.io.*;
-
import javax.microedition.location.*;
-
import java.io.*;
-
-
public class Geocoder extends MIDlet implements CommandListener
-
{
-
public Display display;
-
public Form form;
-
private Command cmdExit,cmdOK;
-
public StringItem si, sili;
-
-
public Geocoder()
-
{
-
-
display =Display.getDisplay(this);
-
form = new Form("Location Api test");
-
cmdExit = new Command("Exit",Command.EXIT,5);
-
cmdOK = new Command("OK",Command.OK,1);
-
si = new StringItem("Coordinates", "Press OK");
-
sili = new StringItem("Location", "");
-
form.append(si);
-
form.append(sili);
-
form.addCommand(cmdOK);
-
form.addCommand(cmdExit);
-
form.setCommandListener(this);
-
}
-
-
public void startApp()
-
{
-
display.setCurrent(form);
-
}
-
-
-
public void pauseApp()
-
{}
-
-
public void destroyApp(boolean flag) {
-
notifyDestroyed();
-
}
-
-
public void commandAction(Command c, Displayable d)
-
{
-
if (c == cmdOK){
-
Retriever ret = new Retriever(this);
-
ret.start();
-
-
} else if (c == cmdExit) {
-
destroyApp(false);
-
}
-
}
-
-
{
-
si.setText(string);
-
}
-
-
Alert alert = new Alert("Alert",message,null,AlertType.WARNING);
-
display.setCurrent(alert,form);
-
}
-
-
-
-
-
}
-
-
-
private Geocoder midlet;
-
Form formRunning;
-
Gauge gauge;
-
-
-
-
public Retriever(Geocoder midlet)
-
{
-
/**
-
* Constructor
-
*
-
* EFFECTS: Initialise the server and store midlet information
-
*
-
* @param midlet The main application midlet
-
* @param server Forecast Server URL
-
*
-
*/
-
this.midlet = midlet;
-
formRunning = new Form("Retrieving Info");
-
formRunning.append(new Gauge("Processing",false,Gauge.INDEFINITE,Gauge.CONTINUOUS_RUNNING));
-
midlet.display.setCurrent(formRunning);
-
-
}
-
-
public void run()
-
{
-
/**
-
* Entry point of the thread
-
*
-
* EFFECTS: call to connect() method
-
*/
-
try {
-
checkLocation();
-
{
-
ex.printStackTrace();
-
midlet.displayString(ex.toString());
-
} finally {
-
-
}
-
-
-
}
-
-
{
-
String string;
-
Location l;
-
LocationProvider lp;
-
Coordinates c;
-
// Set criteria for selecting a location provider:
-
// accurate to 500 meters horizontally
-
Criteria cr= new Criteria();
-
cr.setHorizontalAccuracy(5000);
-
cr.setVerticalAccuracy(5000);
-
-
// Get an instance of the provider
-
lp= LocationProvider.getInstance(cr);
-
-
// Request the location, setting a one-minute timeout
-
l = lp.getLocation(120);
-
c = l.getQualifiedCoordinates();
-
-
if(c != null ) {
-
// Use coordinate information
-
double lat = c.getLatitude();
-
double lon = c.getLongitude();
-
string = "\nLatitude : " + lat + "\nLongitude : " + lon;
-
new GetData(midlet,lat,lon).start();
-
-
} else {
-
string ="Location API failed";
-
}
-
-
formRunning.append("Obtained coordinates...");
-
midlet.displayString(string);
-
}
-
}
-
-
-
Geocoder midlet;
-
double lat, lon;
-
-
public GetData (Geocoder midlet, double lat, double lon) {
-
-
this.lat = lat;
-
this.lon = lon;
-
this.midlet = midlet;
-
-
-
}
-
-
public void commandAction (Command cmd,Displayable disp)
-
{
-
-
}
-
-
public void start() {
-
t.start();
-
}
-
-
-
public void run() {
-
HttpConnection conn=null;
-
InputStream is=null;
-
String sb;
-
-
try {
-
conn = (HttpConnection) Connector.open(sUrl,Connector.READ);
-
if (conn.getResponseCode() == HttpConnection.HTTP_OK) {
-
is = conn.openInputStream();
-
byte buf[] = new byte[128];
-
int total =0;
-
while (total <128) {
-
int count = is.read(buf,total,128-total);
-
if (count<0) {
-
break;
-
}
-
total += count;
-
}
-
-
-
if (sb.length() <10) {
-
midlet.showAlert("Connection error, please try again");
-
is.close();
-
conn.close();
-
-
return;
-
}
-
-
midlet.sili.setText(sb);
-
//midlet.form.append(sb);
-
//vectorized();
-
//midlet.saveCurrency(false,midlet.vector);
-
//midlet.display.setCurrent(midlet.form);
-
} else if (conn.getResponseCode() == HttpConnection.HTTP_NOT_FOUND) {
-
midlet.showAlert("URL not found");
-
-
} else {
-
midlet.showAlert("Server busy or unavailable. Please try again later");
-
}
-
-
midlet.showAlert("Connection failed. You need to authorize this application to access network");
-
midlet.showAlert("Connection failed. Please try again later.");
-
midlet.showAlert(e.toString());
-
e.printStackTrace();
-
//midlet.display.setCurrent(midlet.form);
-
} finally {
-
try {
-
if (is != null) {
-
is.close();
-
}
-
-
if (conn != null) {
-
conn.close();
-
}
-
is =null;
-
conn =null;
-
midlet.display.setCurrent(midlet.form);
-
-
-
}
-
}
-
-
-
{
-
if (s!=null) {
-
int i=0;
-
try {
-
while (true) {
-
int b = (int)s.charAt(i++);
-
if ((b>=0x30 && b<=0x39) || (b>=0x41 && b<=0x5A) || (b>=0x61 && b<=0x7A)) {
-
tmp.append((char)b);
-
}
-
else {
-
tmp.append("%");
-
if (b <= 0xf) tmp.append("0");
-
}
-
}
-
}
-
return tmp.toString();
-
}
-
return null;
-
}
-
}
The code requires mobile device which implements JSR-179 Location API and has been tested on Nokia E71 and 6210 Navigator.
Tags: coordinates, e71, example, geocoder, geocoding, gps, j2me, javame, jsr-179, jsr179, lbs, location-api, locationapi, midlet, midlets, mobile, Nokia, source code, tinygeocoder
TinyGeo-coder : A cool free geocoding/reverse geocoding service
I was searching for a free and easy to use geocoding web service over the internet for my experiment involving Location Based Service (LBS). Then suddenly i came accross tinygeocoder, a web service which really suits my need.
tinygeocoder services that caught my eye :
- geocoding - you can feed it with name of place like "San Francisco, CA" and it will return result in latitude and longitude pair "(37.775196,-122.419204)"
- reverse geocoding - feed it with a coordinate, and the service will return you the name of the corresponding place.
Personally I like the "reverse geocoding" functionality more as it would be handy for my LBS project. Keep an eye for this blog as I'll be posting JavaME JSR-179 (Location API) codes which utilizes tinygeocoder services.
p/s: If you find tinygeoder helpful, consider making donations to them.
Tags: api, codes, example, geo coding, geocoder, geocoding, gps, lbs, location, location-api, maps, mobile, REST, web, Web Service
Pocket SharpMT – Free Pocket PC Blogging Client
Pocket SharpMT is a blogging client for Pocket PC devices. It supports Movable-Type and other blogging platform that supports Movable-Type XML-RPC api like Wordpress and Nucleus CMS.
Among the features supported by Pocket SharpMT are :
- Multiple Category support
- Post Status (Draft/Published)
- Custom Weblog API ping URL
- Post Excerpts
- Image Uploading
- Text Formatting
- Contact-list details export (URL,Email)
The most useful feature that I appreciate most in SharpMT are the multiple category support and post draft saving feature, which is very handy when I'm traveling with my Dopod P800W Pocket PC PDA.
The only feature that I would like to add in SharpMT is support for Pocket PC GPS device. It would be awesome to be able to report your position when you are blogging while you're travelling.
Pocket SharpMT Screenshots
Download Pocket SharpMT
As the name implies, Pocket SharpMT requires .NET Compact Framework 2.0 runtime which is shipped together with devices running Windows Mobile 5.0 and above.
You can download Pocket SharpMT from its official website below :

