此代码存在问题,“无法解析方法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;
}
}
答案 0 :(得分:0)
我相信您已经升级了Google Play服务的依存关系。先前弃用的getMap()函数在Google Play服务SDK中不再可用。 (仍可从提供给Android设备的Google Play服务APK中获得它。)自2014年12月起,不赞成使用getMap()函数。有关将getMap()转换为getMapAsync()的帮助,请参见发布博客。 更多信息https://developers.google.com/maps/documentation/android-sdk/releases