Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a LocationListener alongside the AndEngine game engine
    primarykey
    data
    text
    <p>Hey, I'm currently looking into how to use <a href="http://code.google.com/p/andengine/" rel="nofollow">AndEngine</a> together with the phone's GPS location. I figured it shouldn't be too hard to access this information, so I just grabbed the <a href="http://code.google.com/p/andengineexamples/source/browse/src/org/anddev/andengine/examples/ChangeableTextExample.java" rel="nofollow">ChangeableText</a> example and am trying to tweak it so I can see that it grabs the Location correctly, basically what I have done is: </p> <p>added 'implements LocationListener' to the class declaration</p> <pre><code> public class ChangeableTextExample extends BaseExample implements LocationListener{ </code></pre> <p>added location variables and a location manager to the class fields:</p> <pre><code>private long curlat; private long curlng; private LocationManager locationManager; </code></pre> <p>instantiated the locationManager in the onLoadScene() method:</p> <pre><code>locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); </code></pre> <p>set the elapsedText to print out the curlat and curlng variables:</p> <pre><code> scene.registerUpdateHandler(new TimerHandler(1 / 20.0f, true, new ITimerCallback() { public void onTimePassed(final TimerHandler pTimerHandler) { elapsedText.setText("Location: " + curlat + ", " + curlng); fpsText.setText("FPS: " + fpsCounter.getFPS()); } })); </code></pre> <p>and implement the onLocationChanged(Location arg) method so that it updates the curlat,curlng fields. </p> <pre><code>public void onLocationChanged(Location location) { this.curlat = (long) (location.getLatitude()*1E6); this.curlng = (long) (location.getLongitude()*1E6); } </code></pre> <p>Sadly, this doesn't work, and I was wondering if any of you could point me in the right direction? I'm pretty new to programming for Android, and even newer to programming with AndEngine. I'm guessing it has something to do with the fact that the locationManager isn't properly instantiated?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload