2

I am currently working on a Google Map current location application. Everything is good and there is no error detected.

When I run my application, Google Map is able to load but is not showing my current location.

So I put my logcat here and please someone help me. Is it related to the

"Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources."

? I did some research on this but could not find the solution.

                      1882-1882/com.example.yan.basicmap I/art﹕ Not late-enabling -Xcheck:jni (already on)
04-25 23:40:47.534    1882-1882/com.example.yan.basicmap I/zzx﹕ Making Creator dynamically
04-25 23:40:47.536    1882-1882/com.example.yan.basicmap W/ResourcesManager﹕ Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
04-25 23:40:47.536    1882-1882/com.example.yan.basicmap W/ResourcesManager﹕ Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
04-25 23:40:47.552    1882-1894/com.example.yan.basicmap I/art﹕ WaitForGcToComplete blocked for 15.238ms for cause Background
04-25 23:40:47.698    1882-1882/com.example.yan.basicmap I/Google Maps Android API﹕ Google Play services client version: 7095000
04-25 23:40:47.908    1882-1882/com.example.yan.basicmap I/Google Maps Android API﹕ Google Play services package version: 7097470
04-25 23:40:47.912    1882-1894/com.example.yan.basicmap I/art﹕ Background sticky concurrent mark sweep GC freed 375(38KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 1563KB/1563KB, paused 2.019ms total 257.132ms
04-25 23:40:48.190    1882-1894/com.example.yan.basicmap W/art﹕ Suspending all threads took: 26.203ms
04-25 23:40:48.199    1882-1894/com.example.yan.basicmap I/art﹕ Background partial concurrent mark sweep GC freed 230(18KB) AllocSpace objects, 0(0B) LOS objects, 24% free, 1630KB/2MB, paused 31.158ms total 193.459ms
04-25 23:40:48.752    1882-1894/com.example.yan.basicmap W/art﹕ Suspending all threads took: 9.022ms
04-25 23:40:48.759    1882-1894/com.example.yan.basicmap I/art﹕ Background sticky concurrent mark sweep GC freed 19138(735KB) AllocSpace objects, 2(545KB) LOS objects, 6% free, 8MB/8MB, paused 11.294ms total 74.473ms
04-25 23:40:48.945    1882-1894/com.example.yan.basicmap I/art﹕ Background sticky concurrent mark sweep GC freed 12748(531KB) AllocSpace objects, 0(0B) LOS objects, 2% free, 10MB/10MB, paused 11.798ms total 71.362ms
04-25 23:40:50.436    1882-1894/com.example.yan.basicmap I/art﹕ Background sticky concurrent mark sweep GC freed 1700(149KB) AllocSpace objects, 0(0B) LOS objects, 2% free, 10MB/10MB, paused 4.556ms total 105.593ms
04-25 23:40:50.570    1882-1894/com.example.yan.basicmap I/art﹕ Background partial concurrent mark sweep GC freed 1133(91KB) AllocSpace objects, 0(0B) LOS objects, 15% free, 10MB/12MB, paused 2.771ms total 112.451ms
04-25 23:40:50.580    1882-1916/com.example.yan.basicmap D/OpenGLRenderer﹕ Render dirty regions requested: true
04-25 23:40:50.583    1882-1882/com.example.yan.basicmap D/﹕ HostConnection::get() New Host Connection established 0xa0174c30, tid 1882
04-25 23:40:50.674    1882-1882/com.example.yan.basicmap D/Atlas﹕ Validating map...
04-25 23:40:50.700    1882-1916/com.example.yan.basicmap D/﹕ HostConnection::get() New Host Connection established 0xa015b4c0, tid 1916
04-25 23:40:50.795    1882-1916/com.example.yan.basicmap I/OpenGLRenderer﹕ Initialized EGL, version 1.4
04-25 23:40:50.888    1882-1916/com.example.yan.basicmap D/OpenGLRenderer﹕ Enabling debug mode 0
04-25 23:40:50.962    1882-1916/com.example.yan.basicmap W/EGL_emulation﹕ eglSurfaceAttrib not implemented
04-25 23:40:50.962    1882-1916/com.example.yan.basicmap W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa0f71d20, error=EGL_SUCCESS
04-25 23:40:51.140    1882-1913/com.example.yan.basicmap D/﹕ HostConnection::get() New Host Connection established 0xa0113f10, tid 1913
04-25 23:40:51.735    1882-1882/com.example.yan.basicmap I/MapsActivity﹕ Location services connected.
04-25 23:40:53.899    1882-1894/com.example.yan.basicmap I/art﹕ Background partial concurrent mark sweep GC freed 2315(140KB) AllocSpace objects, 5(827KB) LOS objects, 10% free, 16MB/18MB, paused 1.544ms total 401.616ms
04-25 23:40:59.365    1882-1894/com.example.yan.basicmap I/art﹕ Background partial concurrent mark sweep GC freed 473(30KB) AllocSpace objects, 4(5MB) LOS objects, 10% free, 16MB/18MB, paused 1.382ms total 102.324ms
04-25 23:41:01.378    1882-1882/com.example.yan.basicmap I/Google Maps Android API﹕ Google Play services package version: 7097470
04-25 23:41:01.565    1882-1916/com.example.yan.basicmap W/EGL_emulation﹕ eglSurfaceAttrib not implemented
04-25 23:41:01.565    1882-1916/com.example.yan.basicmap W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa0f71d20, error=EGL_SUCCESS
04-25 23:41:01.708    1882-2003/com.example.yan.basicmap D/﹕ HostConnection::get() New Host Connection established 0x9f066af0, tid 2003
04-25 23:41:01.784    1882-1882/com.example.yan.basicmap I/MapsActivity﹕ Location services connected.
04-25 23:41:03.463    1882-1894/com.example.yan.basicmap I/art﹕ Background partial concurrent mark sweep GC freed 3979(232KB) AllocSpace objects, 10(5MB) LOS objects, 10% free, 17MB/19MB, paused 11.308ms total 39.779ms
Dweeberly
  • 4,668
  • 2
  • 22
  • 41
lemon
  • 23
  • 1
  • 4
  • What does this google map template looks like ? Empty tiles ? I suspect this has something to do with your key. – inmyth Apr 25 '15 at 18:28
  • I mean my application on the emulator can only runs the basic google map, which is exactly the same as new porject -> choosing target android devices -> choose google map activity template. I have installed the necessary SDK like google play service in the SDK manager, and got all permissions I need. But my case is my application did not show my current location. Do I need to put my code here? – lemon Apr 25 '15 at 18:46
  • I'm not going to create a new project to see it. Does the map show blank tile ? Or does it show a map somewhere off coast West Africa ? The first is the problem of key. The second is the position of lat,lng = (0, 0). You need to manually set your own location if that's the case. – inmyth Apr 25 '15 at 18:58
  • The map shows somewhere off coast west africa, seems this is the the start point of google map having 0 lat and lng, but I could not get my current location. – lemon Apr 25 '15 at 19:26

1 Answers1

2

By default a map doesn't show your location. Location is provided by different service: Google Play location API (which supersedes Android location API).

This is a minimum code to implement it. First add these in your manifest

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Then you need to build a GoogleApiClient in your map Activity

public class MyMapActivity extends Activity {

 private GoogleMap googleMap;
 private GoogleApiClient mGoogleApiClient;
 protected Location mLastLocation;

  @Override
  public void onCreate(Bundle inState) {
  // do whatever initialization including one for googleMap
     mGoogleApiClient = new GoogleApiClient.Builder(this)
     .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

          @Override
          public void onConnected(Bundle arg0) {
             // this is where you got your last location
             mLastLocation = LocationServices.FusedLocationApi
             .getLastLocation(mGoogleApiClient);
             // then center on map
             LatLng mLatLng = new LatLng(mLastLocation.getLatitude(),
             mLastLocation.getLongitude());
             googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom
             (mLatLng, 14), 1000, null);

           }

           @Override
             public void onConnectionSuspended(int arg0) {
           }

     })
     .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {

           @Override
           public void onConnectionFailed(ConnectionResult conResult) {
             if (conResult.hasResolution()){
              try{
                conResult.startResolutionForResult(MyMapActivity.this,
                CONNECTION_FAILURE_RESOLUTION_REQUEST);
               }catch(SendIntentException e){
                    e.printStackTrace();
               }                    
              }
             }})
     .addApi(LocationServices.API)
     .build();
  }

}


  @Override
  protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
  }

  @Override
  protected void onStop() {
    super.onStop();
    mGoogleApiClient.disconnect();
  }

This is official how-to for reference.

The next problem is you are using an emulator so you need to emulate a mock position. This link will better explain how: How to emulate GPS location in the Android Emulator?

Community
  • 1
  • 1
inmyth
  • 8,880
  • 4
  • 47
  • 52
  • Thanks inmyth. The last link is the thing I am looking for, its the problem about my emulator console. These few days I was trying to solve the location problem in many different ways and now my problem is finally solved. Thanks again!!! – lemon Apr 26 '15 at 11:09
  • I have 1 more query want to clear, if I want to show the current location without emulate a mock position, the only way is testing on a real device, Am I correct? – lemon Apr 26 '15 at 13:46
  • Yes. In practice device will get present location whose accuracy depends on the access locations settings in the manifest. – inmyth Apr 26 '15 at 14:05