Results 1 to 3 of 3

Thread: gps issue

  1. #1
    nour is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default gps issue

    hi how do i make this work
    it worked earlier but it seems i change something i don't remember
    Java Code:
    public void onLocationChanged(Location loc) {
    			loc.getLatitude();
    			loc.getLongitude();
    			
    		if(loc.getLatitude()== 31.30){
    			if (loc.getLongitude()== 34.45){
    		
    		 Toast.makeText(Gps1Activity.this, "israel", Toast.LENGTH_LONG).show();
    		}
    		}
    		 Toast.makeText(Gps1Activity.this, "error", Toast.LENGTH_LONG).show();
    		}
    in the morning it gave me "Israel"
    but now error why? could it be because it's cloudy now(now it's night)?
    thanks for the helpers

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: gps issue

    It might help if you changed the message so that it toasted the actual coordinates instead of just saying "error".

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: gps issue

    For debugging you should print out the contents of the loc variable so you know what you are comparing against.
    If you properly align the {}s it looks like you will always get the error message part
    Java Code:
    public void onLocationChanged(Location loc) {
                loc.getLatitude();
                loc.getLongitude();
                 
            if(loc.getLatitude()== 31.30){
                if (loc.getLongitude()== 34.45){
             
                    Toast.makeText(Gps1Activity.this, "israel", Toast.LENGTH_LONG).show();
               }
            }
            Toast.makeText(Gps1Activity.this, "error", Toast.LENGTH_LONG).show();
    }
    A problem with comparing floating point numbers using == can be that 35.000004 != 35.0
    but that is probably very close to the waypoint you are looking at.

    I would use something like: Math.abs(lat - 35.0) < 0.0001
    Last edited by Norm; 12-30-2011 at 10:56 PM.

Similar Threads

  1. Same issue as before....
    By hayden06f4i in forum New To Java
    Replies: 4
    Last Post: 11-08-2010, 02:49 AM
  2. Having an issue with this
    By baap30 in forum New To Java
    Replies: 5
    Last Post: 04-23-2010, 06:32 AM
  3. nio issue
    By mawandiadeepak in forum Networking
    Replies: 2
    Last Post: 03-17-2010, 06:23 AM
  4. Issue
    By FlashNinja in forum New To Java
    Replies: 20
    Last Post: 11-28-2009, 10:44 PM
  5. Issue
    By chaitu444 in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 08:49 PM

Tags for this Thread

Posting Permissions

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