• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

is there any way to trigger onLocationChanged other than moving

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to get current location longitudes and latitudes.But without moving to any location.So is there a way to trigger onLocationChanged method without changing location ?
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will only get updates if there *is* a new location. But you will get an initial "update" with the current location no matter what. If that's not sufficient for your purposes please explain in more detail what you're trying to do.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But you will get an initial "update" with the current location no matter what



1)How it get currentlocation without changes.Can you show with example ?

2)When i run belo codes it alway goes to else part ,without any location changes.Can you tell me the way to go inside in if part without location changes.


 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How it get currentlocation without changes.Can you show with example ?


Just register for location updates and you will receive at least one, even if you never move.

When i run belo codes it alway goes to else part ,without any location changes.Can you tell me the way to go inside in if part without location changes.


I've already told you in some other thread that there won't necessarily be a last known location. So any code that relies on there being one is doomed to fail.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

just register for location updates and you will receive at least one, even if you never move.



please look at below code



when i run this code it gives me nullpointer exception.If it always give a location how it gives null pointer.

 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the attachment for nullpointer
null.png
[Thumbnail for null.png]
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which object is null?

Update: I see, lastknownlocation - you already know that it *can* be null, so why are you working with it without checking whether it *is* null first?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lastknownlocation is null.But provider is not null.See the attachment.
provider.png
[Thumbnail for provider.png]
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The provider has nothing to do with it. lastknownlocation is null, then you call a method on it; consequently you get a NPE.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)what is the reason for this ?

2)I have buitin Google Map application in my phone.But it never gives me such a error.It always shoe my location.How they built it ?

3)If this happen there is no way to get rid of it.That means we unable to run my application.Isn't there anay solution ?
 
Tim Moores
Bartender
Posts: 7645
178
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1)what is the reason for this ?


Not sure what you're asking - why you're getting an NPE if you invoke a method on a null object reference? That's how Java works; surely you have encountered that before.

2)I have buitin Google Map application in my phone.But it never gives me such a error.It always shoe my location.How they built it ?


Probably the same way you're trying to program yours. They're just not invoking methods on null object references.

3)If this happen there is no way to get rid of it.That means we unable to run my application.Isn't there anay solution ?


Of course there's a way to solve this. Why do you think there isn't? Why do you not want to check for null before using an object reference?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Of course there's a way to solve this. Why do you think there isn't? Why do you not want to check for null before using an object reference?



it is ok.But what must do in else part.

other thing is if i use criteria.setAccuracy(Criteria.ACCURACY_COARSE); it doesn't give me null pointer most of time.But if i use criteria.setAccuracy(Criteria.ACCURACY_FINE); most of time it gives me null pointer.Is there any connection with these things with null pointer ?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the different between (Criteria.ACCURACY_COARSE) ,(Criteria.ACCURACY_FINE) ?
 
Tim Moores
Bartender
Posts: 7645
178
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's be very clear about one thing: "it" does not give an NPE. Your code -which is improperly not checking an object reference for null before using it- is reponsible, nobody else is. If you had wanted, you could have gotten rid of the problem long ago, by not accessing lastknownlocation if it is null.

I'm not sure what you mean by "else part", I don't see an if statement in the code you last posted. The underlying problem is very simple: there may not always be a last known location. Specifically, when the app is just starting up, there almost certainly won't. All your code needs to do is to check for that, and act accordingly. For example, by not zooming in on a position. You could show a map of New York instead, just so the user has something to look at.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to store last location longitudes & latitudes in my application.So if the lastknowslocation is null i get last location visited and show it.So how to store last visited longitudes & latitudes.
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So how to store last visited longitudes & latitudes.


Shared Preferences: http://developer.android.com/guide/topics/data/data-storage.html#pref

But even then, the very first time the app runs, you will need to decide what to do if there is no last known location. You can't escape this fundamental problem.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this way.
I found that we can get location from cell id also.Then first i search for location from GPS.if lastknown location is null then i try with cell id.So then i amable to get a location anyway.Is it correct ?
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I very much doubt that a cell/network location will always be available when your app is started. And the user may have that turned off to begin with. Do you really want to require an additional permission on something this uncertain?

It seems that you want to fight tooth and nails the notion that there may not be any location available, while in practice it's all too easy to imagine that just that will be the case. Do you really want your app to fail in those circumstances? Why?
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic