Hi,
i have created an app to to find location (lat and long) -which is modified from various sample pieces on this website- and then sms data to predefined mobile device. The app is installed in a nokia 5230 device, it works fine except it uses the internet as a location provider which incurs service provider costs which i am trying to avoid...I have tried forcing it to not incur costs by using the Criteria class setCostAllowed method but that doesn't solve the issue.
i have loaded ovi maps onto the device and it automatically locates the devices postion when the Maps application is opened,
How exactly is ovi maps doing this without internet access? using i presume a mixture of cell info/gps sattelite information/installed ovi maps...
does anyone know how i can get my application to do likewise? to ie find it's location without using internet access?
my code, is below, contains the midlet and one extra class called network..
any pointers on this greatly appreciated...
ps tried using
package sendGPS_googleMapsURL;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.location.Coordinates;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationProvider;
import javax.microedition.midlet.MIDlet;
public class SendPosURL extends MIDlet implements CommandListener {
private Display display;
private Form form;
private Command exitCommand;
private Command refreshCommand;
private Command sendCommand;
private StringItem text;
private Location location;
private LocationProvider locationProvider;
private Coordinates coordinates;
private Criteria criteria;
private String smsString;
public SendPosURL() {
form = new Form("BscH4 Project _Locator_Rory O'Flynn");
sendCommand = new Command("Send Position",Command.OK,2);
exitCommand = new Command("Exit", Command.EXIT, 3);
refreshCommand = new Command("Position", Command.OK, 1);
smsString = "; sending text from string2";
text = new StringItem("Your position:", "\nSelect \"Position\"");
form.append(text);
form.addCommand(exitCommand);
form.addCommand(refreshCommand);
form.addCommand(sendCommand);
form.setCommandListener(this);
display = Display.getDisplay(this);
display.setCurrent(form);
criteria = new Criteria();
criteria.setHorizontalAccuracy(500);
// the following tells the Location API not to
//incur costs when getting coordinates
// criteria.setCostAllowed(false);
try {
locationProvider = LocationProvider.getInstance(criteria);
} catch (LocationException e) {
//TODO: Handle location exception.
return;
}
if (locationProvider == null ) {
text.setText("Location API failed.");
form.removeCommand(refreshCommand);
}
}
public void startApp() {
// No implementation required.
}
public void pauseApp() {
// No implementation required.
}
public void destroyApp(boolean unconditional) {
// No implementation required
}
public void commandAction(Command c, Displayable d) {
if (c == refreshCommand) {
checkLocation();
}
else if (c == sendCommand) {
sendSMS();
}
else if (c == exitCommand) {
notifyDestroyed();
}
}
/**
* Called to read current location.
*/
private void checkLocation() {
String string;
try {
location = locationProvider.getLocation(100);
} catch (LocationException e) {
//TODO: Handle exception.
return;
} catch (InterruptedException e) {
//TODO: Handle exception.
return;
}
coordinates = location.getQualifiedCoordinates();
if (coordinates != null) {
// Use coordinate information
double lat = coordinates.getLatitude();
double lon = coordinates.getLongitude();
string = "http://maps.google.com/maps?q=" + lat + " " + lon;
} else {
string = "Calculating position, no fix yet.";
}
smsString = string;
text.setText(string);
}
private void sendSMS(){
// SendGPS s = new SendGPS(smsString);
Network n = new Network ();
n.sendSms(smsString);
text.setText("sending text" + smsString);
}
}
===========================================================
package sendGPS_googleMapsURL;
import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
public class Network {
public Network ()
{};
//public boolean sendSms(String number, String message){
//Rory changed method signature to below
public boolean sendSms( String message){
boolean result = true;
try {
String addr = "sms://+353877525656";
// opens connection
MessageConnection conn = (MessageConnection) Connector.open(addr);
// prepares text message
TextMessage msg =
(TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
//set text
msg.setPayloadText(message);
// send message
conn.send(msg);
} catch (Exception e) {
result = false;
}
return result;
}
}

Reply With Quote

