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

时间:2017-04-07 17:17:23

标签: android google-maps

我创建了一个Android移动应用,该应用使用Google Maps API生成一个简单的地图并在其上添加标记。

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();

        }

    }
});

1 个答案:

答案 0 :(得分:2)

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

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;
    }