Android的谷歌地图没有显示我的位置? [英] Android Google Map not showing my location?

查看:510
本文介绍了Android的谷歌地图没有显示我的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个谷歌地图的当前位置的应用程序。一切都很好,没有检测到的错误。

当我跑我的应用程序,谷歌地图是能够加载,但没有显示我的当前位置。

所以我把我的logcat这里请人帮助我。这是否与该


  

资产路径/system/framework/com.android.media.remotedisplay.jar
  不存在或不包含任何资源。


?我做了这方面的一些研究,但未能找到解决方案。

  1882年至1882年/ com.example.yan.basicmap I /艺术:不晚启用-Xcheck:JNI(已上)
04-25 23:40:47.534 1882年至1882年/ com.example.yan.basicmap I / ZZX:让造物主动态
04-25 23:40:47.536 1882年至1882年/ com.example.yan.basicmap W / ResourcesManager:资产路径/system/framework/com.android.media.remotedisplay.jar'不存在或不包含任何资源。
04-25 23:40:47.536 1882年至1882年/ com.example.yan.basicmap W / ResourcesManager:资产路径/system/framework/com.android.location.provider.jar'不存在或不包含任何资源。
04-25 23:40:47.552 1882年至1894年/ com.example.yan.basicmap I /艺术:WaitForGcToComplete阻塞15.238ms的背景原因
04-25 23:40:47.698 1882年至1882年/ com.example.yan.basicmap I /谷歌地图API的Andr​​oid:谷歌Play服务的客户端版本:7095000
04-25 23:40:47.908 1882年至1882年/ com.example.yan.basicmap I /谷歌地图API的Andr​​oid:谷歌播放服务包的版本:7097470
04-25 23:40:47.912 1882年至1894年/ com.example.yan.basicmap I /艺术:背景粘并发标记扫描GC释放375(38KB)AllocSpace对象,0(0B)LOS对象,0%免费,1563KB / 1563KB,暂停2.019ms总257.132ms
04-25 23:40:48.190 1882年至1894年/ com.example.yan.basicmap W /艺术:暂停所有线程了:26.203ms
04-25 23:40:48.199 1882年至1894年/ com.example.yan.basicmap I /艺术:背景部分并发标记扫描GC释放230(18KB)AllocSpace对象,0(0B)LOS对象,24%免费,1630KB / 2MB,暂停31.158ms总193.459ms
04-25 23:40:48.752 1882年至1894年/ com.example.yan.basicmap W /艺术:暂停所有线程了:9.022ms
04-25 23:40:48.759 1882年至1894年/ com.example.yan.basicmap I /艺术:背景粘并发标记扫描GC释放19138(735KB)AllocSpace对象,2(545KB)LOS对象,6%免费,8MB / 8MB,暂停11.294ms总74.473ms
04-25 23:40:48.945 1882年至1894年/ com.example.yan.basicmap I /艺术:背景粘并发标记扫描GC释放12748(531KB)AllocSpace对象,0(0B)LOS对象,2%免费,10MB / 10MB,暂停11.798ms总71.362ms
04-25 23:40:50.436 1882年至1894年/ com.example.yan.basicmap I /艺术:背景粘并发标记扫描GC释放1700(149KB​​)AllocSpace对象,0(0B)LOS对象,2%免费,10MB / 10MB,暂停4.556ms总105.593ms
04-25 23:40:50.570 1882年至1894年/ com.example.yan.basicmap I /艺术:背景部分并发标记扫描GC释放1133(91KB)AllocSpace对象,0(0B)LOS对象,15%的自由,10MB / 12MB,暂停2.771ms总112.451ms
04-25 23:40:50.580 1882年至1916年/ com.example.yan.basicmap D / OpenGLRenderer:渲染脏区要求:真
04-25 23:40:50.583 1882年至1882年/ com.example.yan.basicmap D /:HostConnection ::得到()新主机连接建立0xa0174c30,TID 1882
04-25 23:40:50.674 1882年至1882年/ com.example.yan.basicmap D /图集:验证地图...
04-25 23:40:50.700 1882年至1916年/ com.example.yan.basicmap D /:HostConnection ::得到()新主机连接建立0xa015b4c0,TID 1916年
04-25 23:40:50.795 1882年至1916年/ com.example.yan.basicmap I / OpenGLRenderer:初始化EGL,1.4版本
04-25 23:40:50.888 1882年至1916年/ com.example.yan.basicmap D / OpenGLRenderer:启用调试模式0
04-25 23:40:50.962 1882年至1916年/ com.example.yan.basicmap W / EGL_emulation:eglSurfaceAttrib没有实现
04-25 23:40:50.962 1882年至1916年/ com.example.yan.basicmap W / OpenGLRenderer:无法设置EGL_SWAP_BEHAVIOR表面0xa0f71d20错误= EGL_SUCCESS
04-25 23:40:51.140 1882年至1913年/ com.example.yan.basicmap D /:HostConnection ::得到()新主机连接建立0xa0113f10,TID 1913年
04-25 23:40:51.735 1882年至1882年/ com.example.yan.basicmap I / MapsActivity:位置服务相连接。
04-25 23:40:53.899 1882年至1894年/ com.example.yan.basicmap I /艺术:背景部分并发标记扫描GC释放2315(140KB)AllocSpace对象,5(827KB)LOS对象,10%免费,16MB / 18MB,暂停1.544ms总401.616ms
04-25 23:40:59.365 1882年至1894年/ com.example.yan.basicmap I /艺术:背景部分并发标记扫描GC释放473(30KB)AllocSpace对象,4(5MB)LOS对象,10%免费,16MB / 18MB,暂停1.382ms总102.324ms
04-25 23:41:01.378 1882年至1882年/ com.example.yan.basicmap I /谷歌地图API的Andr​​oid:谷歌播放服务包的版本:7097470
04-25 23:41:01.565 1882年至1916年/ com.example.yan.basicmap W / EGL_emulation:eglSurfaceAttrib没有实现
04-25 23:41:01.565 1882年至1916年/ com.example.yan.basicmap W / OpenGLRenderer:无法设置EGL_SWAP_BEHAVIOR表面0xa0f71d20错误= EGL_SUCCESS
04-25 23:41:01.708 1882年至2003年/ com.example.yan.basicmap D /:HostConnection ::得到()新主机连接建立0x9f066af0,TID 2003
04-25 23:41:01.784 1882年至1882年/ com.example.yan.basicmap I / MapsActivity:位置服务相连接。
04-25 23:41:03.463 1882年至1894年/ com.example.yan.basicmap I /艺术:背景部分并发标记扫描GC释放3979(232KB)AllocSpace对象,10(5MB)LOS对象,10%免费,17MB / 19MB,暂停11.308ms总39.779ms


解决方案

默认地图不显示你的位置。位置是由不同的服务提供的:谷歌播放位置API(其中取代 Android的定位API)。

这是一个最低code来实现它。
首先在你的清单中添加这些

 <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>

然后,你需要在地图的活动,以建立一个GoogleApiClient

 公共类MyMapActivity延伸活动{ 私人GoogleMap的GoogleMap的;
 私人GoogleApiClient mGoogleApiClient;
 受保护的位置mLastLocation;  @覆盖
  公共无效的onCreate(捆绑安置){
  //做任何初始化,包括一个用于GoogleMap的
     mGoogleApiClient =新GoogleApiClient.Builder(本)
     .addConnectionCallbacks(新GoogleApiClient.ConnectionCallbacks(){          @覆盖
          公共无效onConnected(捆绑为arg0){
             //这是你有你的最后一个位置
             mLastLocation = LocationServices.FusedLocationApi
             .getLastLocation(mGoogleApiClient);
             //然后在地图中心
             经纬度mLatLng =新的经纬度(mLastLocation.getLatitude()
             mLastLocation.getLongitude());
             googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom
             (mLatLng,14),1000,NULL);           }           @覆盖
             公共无效onConnectionSuspended(INT为arg0){
           }     })
     .addOnConnectionFailedListener(新GoogleApiClient.OnConnectionFailedListener(){           @覆盖
           公共无效onConnectionFailed(ConnectionResult conResult){
             如果(conResult.hasResolution()){
              尝试{
                conResult.startResolutionForResult(MyMapActivity.this,
                CONNECTION_FAILURE_RESOLUTION_REQUEST);
               }赶上(SendIntentException E){
                    e.printStackTrace();
               }
              }
             }})
     .addApi(LocationServices.API)
     。建立();
  }}
  @覆盖
  保护无效调用onStart(){
    super.onStart();
    mGoogleApiClient.connect();
  }  @覆盖
  保护无效的onStop(){
    super.onStop();
    mGoogleApiClient.disconnect();
  }

这是官员如何对的参考。

接下来的问题是,你使用的是仿真器,所以你需要模拟一个模拟的位置。此链接将更好地解释如何:<一href=\"http://stackoverflow.com/questions/2279647/how-to-emulate-gps-location-in-the-android-emulator\">How效仿在Android模拟器的GPS位置?

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

解决方案

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?

这篇关于Android的谷歌地图没有显示我的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆