Android 手机和模拟器中的mapView不同

2024-02-21

关于应用程序:--这是一个简单的应用程序,可以查找用户当前位置。

问题:-- 该应用程序在模拟器上运行良好,请参见图片。

但在手机中它没有显示MapView。请看图片。

请告诉我手机出了什么问题。在手机中,它只下载巨大的(20 MB)数据,但不显示实际地图。

Logcat 我得到 -

   10-31 16:44:45.994: E/MapActivity(3026): Couldn't get connection factory client

  10-31 15:47:42.319: ERROR/MapView(1773): java.lang.IllegalStateException: Null Bitmap!   "loading_tile"; if seen during a test, this usually means that the image file needs to be added to the test.config file

XML FILE

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<TextView  
android:id="@+id/myLocationText"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" />

 <com.google.android.maps.MapView
 android:id="@+id/myMapView"
 android:layout_height="fill_parent"
 android:layout_width="fill_parent"
 android:clickable="true"
 android:enabled="true"
 android:apiKey="0bBgLl42nWwnTf983Y5VdIgfZI6mC7meL7Ms_qg"/>

</LinearLayout>

Code

public class WhereIam extends MapActivity {
MapController mapController;
MyPositionOverlay positionOverlay;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView myMapView=(MapView)findViewById(R.id.myMapView);
    mapController=myMapView.getController();
    myMapView.setSatellite(true);
    myMapView.setStreetView(true);
    myMapView.displayZoomControls(false);
    myMapView.setBuiltInZoomControls(true);
    mapController.setZoom(16);
    positionOverlay = new MyPositionOverlay();
    List<Overlay> overlays = myMapView.getOverlays();
    overlays.add(positionOverlay);
    LocationManager locationManager;
    String context=Context.LOCATION_SERVICE;
    locationManager=(LocationManager)getSystemService(context);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    String provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);

    final LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
        updateWithNewLocation(location);
        }
        public void onProviderDisabled(String provider){
        updateWithNewLocation(null);
        }
        public void onProviderEnabled(String provider){ }
        public void onStatusChanged(String provider, int status,
        Bundle extras){ }
        };

    updateWithNewLocation(location);
    locationManager.requestLocationUpdates(provider, 2000, 10,
            locationListener);
}

private void updateWithNewLocation(Location location) {
    String latLongString;
    TextView myLocationText;
    String addressString ="No Address Found";
    myLocationText=(TextView)findViewById(R.id.myLocationText);
    if(location!=null)  {
        // Update the map location.
        positionOverlay.setLocation(location);
        Double geoLat = location.getLatitude()*1E6;
        Double geoLng = location.getLongitude()*1E6;
        GeoPoint point = new GeoPoint(geoLat.intValue(),
        geoLng.intValue());
        mapController.animateTo(point);
        double lat=location.getLatitude();
        double lng=location.getLongitude();
        latLongString = "Lat:" + lat + "\nLong:" + lng;
        Geocoder gc=new Geocoder(this, Locale.getDefault());
        try {
            List<Address> addressess= gc.getFromLocation(lat, lng, 1);
            StringBuilder sb=new StringBuilder();
            if(addressess.size()>0) {
                Address address=addressess.get(0);
                for(int i=0;i<address.getMaxAddressLineIndex();i++) {
                    sb.append(address.getAddressLine(i)).append("\n");
                    sb.append(address.getLocality()).append("\n");
                    sb.append(address.getPostalCode()).append("\n");
                    sb.append(address.getCountryName());
                }
                addressString = sb.toString();
            }
        }catch(IOException e) {} 
    }
    else {
        latLongString="No Found Location";
    }
    myLocationText.setText("Your current Location is \n"+latLongString+"\n"+addressString);
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

}

我刚刚按照 goto->cmd 提示符创建了一个 api 密钥

将目录更改为 keytool 文件夹

现在运行命令 keytool -list -alias androiddebugkey -keystore "C:\Users\pc.android\debug.keystore" -storepass android -keypass android

see the image enter image description here

现在我转到注册页面,我只需将 MD5 放入 EditText 并选中接受并单击“生成密钥”,然后出现以下页面,其中显示密钥 -

enter image description here Now i put this key in my MapView Xml file..

正如您可以看到应用程序在模拟器中运行良好但在真实手机中运行不佳。

我哪里出错了,如何为真实手机生成第二个 API 密钥?


为了在真实硬件上进行测试,您需要使用与调试密钥不同的密钥。在您的帖子之后,您正在使用调试密钥库。

https://developers.google.com/maps/documentation/android-api/v1/?csw=1#getfingerprint https://developers.google.com/maps/documentation/android-api/v1/?csw=1#getfingerprint

在谷歌上阅读该段落。

重要的是,应用程序导出为签名应用程序,并使用与 google api 相同的密钥(而不是调试密钥)。

要创建有效的内容,请阅读该段落:

http://developer.android.com/guide/publishing/app-signing.html#releasemode http://developer.android.com/guide/publishing/app-signing.html#releasemode

然后使用相同的密钥获取 google 地图 api 密钥。

获得应用程序的密钥后,您可以通过在项目上单击鼠标右键选择 Android Tools,然后导出为签名的应用程序包并按照向导操作来导出签名的应用程序(也许您可以使用该命令创建一个新密钥)向导)。

希望有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 手机和模拟器中的mapView不同 的相关文章

随机推荐

  • 哈希表中关键内容的最佳实践

    最好的查找结构是HashTable 它提供持续的访问一般 最坏情况下呈线性 这取决于哈希函数 好的 我的问题如下 假设一个良好的实施HashTable e g HashMap关于映射中传递的键是否有最佳实践 我的意思是建议键必须是不可变的对
  • 为什么这个从未来列表到未来列表的转换能够编译并起作用?

    免责声明 下面的代码片段与正在进行的 Coursera 课程之一相关 我们假设它只是出于学习目的而发布 不应用于作为家庭作业的解决方案提交 正如下面的评论所述 我们需要将 Future 列表转换为列表的单个 Future 更重要的是 如果至
  • 如果条件唯一,MySQL 的非重复计数

    我正在尝试构建一个查询 告诉我给定数据集中有多少个不同的女性和男性 该人通过号码 电话 来识别 同一个 tel 可以出现多次 但该 tel 的性别只能计算一次 7136609221 男7136609222 男7136609223 女7136
  • 具有多个组的导航视图根据条件隐藏和显示组

    I have NavigationView具有多个组 基于某些条件我需要隐藏和显示组 我怎样才能实现这个目标 我的样品NavigationView menu menu menu
  • 我该如何修改这个SQL语句呢?

    我的 SQL Server 视图 SELECT geo HyperLinks CatID geo Tags Tag geo HyperLinks HyperLinksID FROM geo HyperLinks LEFT OUTER JOI
  • 快速 cookie 返回未定义

    我试图在express js 上设置cookie 但它返回未定义 我搜索了很多网页并把express cookieParser above app use app router 但它仍然无法返回正确的值 app js app configu
  • 平滑画布动画

    我正在尝试学习如何使用 HTML5 的画布创建流畅的 JavaScript 动画 由于某种原因 动画并不流畅 而是有点 溅射 你可以看到我构建的框架这个jsFiddle http jsfiddle net 3TAVu 目前仅使用 Webki
  • C++ 模板“延迟实例化”

    C 模板中的 延迟实例化 是什么意思 延迟实例化是指直到第一次使用相应实体时才实例化模板 例如 您有一个模板化函数 template
  • javascript创建多维数组语法[重复]

    这个问题在这里已经有答案了 今天我听说可以使用以下语法在 js 中创建多维数组 var a new Array 3 3 a 2 2 2 alert a 2 2 然而这在歌剧中不起作用 我有什么地方说错了吗 是的 你有地方错了 var a n
  • git 存储库在 Linux 中从 jenkins 连接时出现 403 错误

    嗨 我只想将我的项目从 github 配置到 jenkins 来生成 build gradle 文件 我收到以下错误 Failed to connect to repository Command usr bin git ls remote
  • 如何在IPython中自动设置默认路径

    我使用 WingIDE 进行开发 使用 Ipython 运行脚本 我在几个方面面临一些不便 每当我更新代码时 我都必须重新加载模块才能在 IPython 中更新它 为了解决我遵循的问题绳文杉 https stackoverflow com
  • 如何从 jenkins 构建 Visual Studio 安装程序项目(.vdproj)以生成 .exe 和 .msi 文件?

    我有一个 Visual Studio 安装程序项目 vdproj 我想从 jenkins 构建它 有人可以为我提供解决方案吗 我尝试使用 msbuild 但它不适合我 然后我在批处理文件中尝试了以下操作 devenv exe pathToP
  • AngularUI:为什么模态没有作为指令实现?

    我在我的项目中使用 Angular ui 我想实现一个模式窗口 库的大部分组件 http angular ui github io bootstrap http angular ui github io bootstrap 作为指令实现 如
  • 在 GWT 中需要应用程序范围的 CSS 常量

    我想在 GWT CssResource 中将一些颜色定义为常量 并在整个应用程序中使用这些常量 但我不知道该怎么做 我会告诉你我已经尝试过什么 我创建了一个 ClientBundle 和一个 CssResource 如下所示 public
  • 将 SDL2 库与 pkg-config 链接

    我使用的是 Ubuntu 14 04LTS 我已经通过从源代码编译安装了 SDL2 库 方法 1https askubuntu com questions 344512 what is the general procedure to in
  • 谷歌分析的 setCredentialStore 方法的替代方法

    我使用以下代码来授权已安装的应用程序访问用户的受保护数据 private Analytics iniAnalytics String secureFolder try HttpTransport httpTransport GoogleNe
  • 与 WhenAll 并行执行任务时的任务缓存

    所以我有这个小代码块 它将并行执行多个任务 no wrapping in Task it is async var activityList await dataService GetActivitiesAsync Select a goo
  • React Native:如何导出带有返回值的方法?

    在 React Native 中导出带有返回值的方法的最佳方法是什么 我知道有RCT EXPORT METHOD 但这仅适用于以下方法 void 因此不要返回任何东西 最好我不需要导出整个类 只需导出一些方法 另一种选择是进行回调 但我想尽
  • sklearn 逻辑回归“ValueError:找到的数组暗淡为 3。预计估计器 <= 2。”

    我尝试解决此笔记本中的问题 6 https github com tensorflow examples blob master courses udacity deep learning 1 notmnist ipynb 问题是使用 50
  • Android 手机和模拟器中的mapView不同

    关于应用程序 这是一个简单的应用程序 可以查找用户当前位置 问题 该应用程序在模拟器上运行良好 请参见图片 但在手机中它没有显示MapView 请看图片 请告诉我手机出了什么问题 在手机中 它只下载巨大的 20 MB 数据 但不显示实际地图