Android Google Maps OnMapReadyCallback() 未在设备上发生(适用于模拟器)

标签 android google-maps

我创建了一个 Android 移动应用程序,它使用 Google Maps API 生成简单的 map 并在其上放置标记。

在 Android 模拟器中一切正常,但是当我使用 Android 设备时,mapView.getMapAsync 不会触发我的 OnMapReadyCallback()。

我注意到的另一件事是我收到这些消息,不确定它们是否与问题有关。我尝试更新 SDK 中的所有内容,但这些消息始终没有消失:

04-07 20:36:30.990 10487-10487/it.bitrack.fabio.bitrack W/GooglePlayServicesUtil: Google Play services out of date.  Requires 10298000 but found 9879448
04-07 20:36:30.992 10487-10487/it.bitrack.fabio.bitrack W/GooglePlayServicesUtil: Google Play services out of date.  Requires 10298000 but found 9879448
04-07 20:36:30.993 10487-10487/it.bitrack.fabio.bitrack W/GooglePlayServicesUtil: Google Play services out of date.  Requires 10298000 but found 9879448
04-07 20:36:30.994 10487-10487/it.bitrack.fabio.bitrack W/GooglePlayServicesUtil: Google Play services out of date.  Requires 10298000 but found 9879448

你知道为什么吗?我的代码如下...

代码:

mapView.getMapAsync(new OnMapReadyCallback() {
    @Override
    public void onMapReady(GoogleMap googleMap) {
        map = googleMap;
        map.addMarker(new MarkerOptions()
        .position(new LatLng(asset.latitude, asset.longitude))
        .title(asset.networkAssetCode));
        map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(asset.latitude, asset.longitude), 17));

        lastSeenTextView.setText("Last seen: " + asset.datetime);

        try {

            r.getLocationFromCoordinates(asset.latitude, asset.longitude, new Callback() {
                @Override public void onFailure(Call call, IOException e) {
                    e.printStackTrace();
                }

                @Override public void onResponse(Call call, Response response) throws IOException {
                    try (final ResponseBody responseBody = response.body()) {
                        if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

                        Headers responseHeaders = response.headers();
                        for (int i = 0, size = responseHeaders.size(); i < size; i++) {
                            System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
                        }

                        final String result = responseBody.string();
                        Log.i("BiTrack", "Google Reverse Geolocation\n" + result);

                        try {

                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {

                                    Json j = new Json();

                                    updateMapView(j.getAddressFromGeolocationCoordinates(result));

                                }
                            });

                            } catch (Exception e) {

                            e.printStackTrace();

                        }
                    }
                }
            });

            } catch (Exception e) {

            e.printStackTrace();

        }

    }
});

最佳答案

我可以通过添加我在另一个问题中找到的一段代码来解决这个问题:

GooglePlayServicesUtil: Google Play services out of date. Requires 5089000 but found 5077534

private boolean checkPlayServices() {
        GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
        int result = googleAPI.isGooglePlayServicesAvailable(getContext());
        if(result != ConnectionResult.SUCCESS) {
            if(googleAPI.isUserResolvableError(result)) {
                googleAPI.getErrorDialog(getActivity(), result,
                        PLAY_SERVICES_RESOLUTION_REQUEST).show();
            }

            return false;
        }

        return true;
    }

关于Android Google Maps OnMapReadyCallback() 未在设备上发生(适用于模拟器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43283776/

相关文章:

postgresql - ST_MakeEnvelope 与谷歌地图坐标问题

android - 谷歌地图无法在普通设备上加载,但会在测试设备(真实设备)上加载

php - 将google map 加载到ajax加载的div中

javascript - Google Maps Geolocation API 的替代品

java - 更新 SQLite 数据库 Android RecyclerView Iterate

Android 熄屏语音识别?

java - 如何从 ViewPager 的 onPageSelected 异步任务到 fragment ?

javascript - 使用ajax将php数组传递给javascript

android - Android 中的安全枚举自定义属性

android - 当视频播放在 Android 上结束时,Javascript 结束事件