首页 > 解决方案 > 无法解析方法 getmap() 扩展 SupportMapFragment

问题描述

我对此代码有问题,“无法解决方法 getMap()。我找不到问题出在哪里,请需要代码帮助,我使用 Android Studio,需要使用 Json 获取标记位置。我不明白如何更新此代码根据太新的更改。请根据新代码更正此代码,。

class MapFragment extends SupportMapFragment implements IPageChanged {
    public static final String ARG_ITEM_ID = "item_id";
    private String firstLine = null;
    private boolean isCountry;
    private CountryDetail mCountryData;
    private LocationData mLocationData;
    private CountryDetail preData;
    private float previousZoomLevel;
    private String secondLine = null;

    class C14782 implements InfoWindowAdapter {
        C14782() {
        }

        public View getInfoWindow(Marker arg0) {
            return null;
        }

        public View getInfoContents(Marker latLng) {
            View v = null;
            if (MapFragment.this.getActivity() != null) {
                v = MapFragment.this.getActivity().getLayoutInflater().inflate(R.layout.info_window_layout, null);
                TextView cap = (TextView) v.findViewById(R.id.tv_cap);
                cap.setText(MapFragment.this.secondLine);
                ((TextView) v.findViewById(R.id.tv_country)).setText(MapFragment.this.firstLine);
                TextView continent = (TextView) v.findViewById(R.id.tv_continent);
                ImageView ivflag = (ImageView) v.findViewById(R.id.iv_flag);
                if (MapFragment.this.isCountry) {
                    continent.setText(String.valueOf(MapFragment.this.mCountryData.getContinentName()));
                    ivflag.setImageBitmap(AppUtil.getFlag(MapFragment.this.getActivity(), MapFragment.this.mCountryData.getCode()));
                } else {
                    cap.setText(AppUtil.getStringResourceByName(MapFragment.this.getActivity(), "c" + MapFragment.this.secondLine));
                    continent.setVisibility(View.GONE);
                    ivflag.setVisibility(View.GONE);
                }
            }
            return v;
        }
    }

    class C14793 implements OnInfoWindowClickListener {
        C14793() {
        }

        public void onInfoWindowClick(Marker marker) {
            Uri url = Uri.parse("http://en.m.wikipedia.org/wiki/" + MapFragment.this.mLocationData.getName().replaceAll(" ", "_"));
            Intent urlIntent = new Intent("android.intent.action.VIEW");
            urlIntent.setData(url);
            MapFragment.this.getActivity().startActivity(urlIntent);
        }
    }

    public void onCreate(Bundle savedInstanceState) {
        LocationData locationData;
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        Parcelable p = bundle.getParcelable("country");
        if (p == null) {
            locationData = (LocationData) bundle.getParcelable("location");
        } else {
            locationData = (LocationData) p;
            this.isCountry = true;
            if (locationData instanceof CountryDetail) {
                this.mCountryData = (CountryDetail) locationData;
            }
        }
        this.mLocationData = locationData;
    }

    private void dropPinEffect(Marker marker) {
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final Interpolator interpolator = new BounceInterpolator();
        final Marker marker2 = marker;
        handler.post(new Runnable() {
            public void run() {
                float t = Math.max(TextTrackStyle.DEFAULT_FONT_SCALE - interpolator.getInterpolation(((float) (SystemClock.uptimeMillis() - start)) / 1500.0f), 0.0f);
                marker2.setAnchor(0.5f, (14.0f * t) + TextTrackStyle.DEFAULT_FONT_SCALE);
                if (((double) t) > 0.0d) {
                    handler.postDelayed(this, 15);
                } else {
                    marker2.showInfoWindow();
                }
            }
        });
    }

    public void updateMapLocation() {
        if (this.mLocationData != null) {
            GoogleMap map = getMap();
            if (map != null) {
                map.clear();
                LatLng latLng = new LatLng((double) this.mLocationData.getLatitude(), (double) this.mLocationData.getLongitude());
                if (this.isCountry) {
                    this.firstLine = this.mCountryData.getName();
                    this.secondLine = "©" + this.mCountryData.getCapital();
                } else {
                    this.firstLine = this.mLocationData.getName();
                    this.secondLine = this.mLocationData.getContinent();
                }
                Marker marker = map.addMarker(new MarkerOptions().position(latLng).title(this.firstLine).snippet(this.secondLine));
                marker.showInfoWindow();
                if (this.preData == null || !this.mCountryData.getCode().equals(this.preData.getCode())) {
                    dropPinEffect(marker);
                } else {
                    marker.showInfoWindow();
                }
                map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 3.0f));
                map.setOnInfoWindowClickListener(getInfoWindowClickListener());
                map.setInfoWindowAdapter(new C14782());
            }
        }
    }

    public OnInfoWindowClickListener getInfoWindowClickListener() {
        return new C14793();
    }

    public void onPageSelected(BaseActivity activity, int index) {
        if (index == 1 || !(activity instanceof CountryDetailActivity)) {
            updateMapLocation();
        }
        this.preData = this.mCountryData;
    }
}

标签: androidandroid-studio

解决方案


我相信您已经升级了您的 google play 服务依赖项。之前已弃用的 getMap() 函数在 Google Play 服务 SDK 中不再可用。(它仍然在提供给 Android 设备的 Google Play 服务 APK 中可用。)自 2014 年 12 月起,getMap() 函数已被弃用。有关从 getMap() 转换为 getMapAsync() 的帮助,请参阅发布博客文章。更多信息https://developers.google.com/maps/documentation/android-sdk/releases


推荐阅读