Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Feb 2010

    using Criteria class to avoid location costs

    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\"");


    display = Display.getDisplay(this);

    criteria = new Criteria();
    // 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.

    if (locationProvider == null ) {
    text.setText("Location API failed.");

    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) {
    else if (c == sendCommand) {
    else if (c == exitCommand) {

    * Called to read current location.
    private void checkLocation() {
    String string;
    try {
    location = locationProvider.getLocation(100);
    } catch (LocationException e) {
    //TODO: Handle exception.
    } catch (InterruptedException e) {
    //TODO: Handle exception.

    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;


    private void sendSMS(){
    // SendGPS s = new SendGPS(smsString);
    Network n = new Network ();

    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 =
    //set text
    // send message
    } catch (Exception e) {
    result = false;
    return result;

  2. #2
    Registered User
    Join Date
    Feb 2010

    Re: using Criteria class to avoid location costs

    Hi Rory

    Have you tried adjusting the settings on the phone itself, to control the manner in which position is determined? As a developer you have some choice on whether to pay or not, but its usually a customer choice - there is no sense in retricting the end user...

    You should also be testing for the return value of getInstance to determine the success of your chosen Criteria.

    Hope this is helpful.



  3. #3
    Registered User
    Join Date
    Feb 2010

    Re: using Criteria class to avoid location costs

    Hi Des, belated thanks for your response...

Similar Threads

  1. Issue when trying to generate .sis file
    By rmulam in forum Symbian Tools & SDKs
    Replies: 9
    Last Post: 2009-08-13, 14:10
  2. Error Error where are u ??
    By Abhishek_karmakar in forum Symbian
    Replies: 14
    Last Post: 2008-10-20, 09:29
  3. C++ Symbols class(), class()->,class. ????
    By PACALA_BA in forum Symbian
    Replies: 7
    Last Post: 2008-09-15, 20:57
  4. 求助:没有调用到包的问题
    By youpengli in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 1
    Last Post: 2004-05-10, 03:03
  5. 求助:N9200 Series SDK上的问题
    By youpengli in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 3
    Last Post: 2004-05-10, 02:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts