SAN*_*SAN 37 android google-maps google-maps-api-2 google-play-services
我正在尝试在Android应用程序中使用Google map API v2显示简单的地图.我正在遵循Map API文档说明.但我认为这onMapReady并不是出于某种原因.我正在使用google-play-services_lib版本6587000.我的手机有google-play-services_lib其它版本6587038,我相信.
Google地图正在使用初始控件.有人可以帮我纠正这个错误吗?
public class MapDisplay extends FragmentActivity
implements OnMapReadyCallback {
private GoogleMap mMap;
private Location mCurrentLocation;
private MarkerOptions mMarkerOptions ;
private MapFragment mMapFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_map);
/** not needed
mMapFragment = MapFragment.newInstance();
FragmentTransaction fragmentTransaction =
getFragmentManag
er().beginTransaction();
fragmentTransaction.add(R.id.map, mMapFragment);
fragmentTransaction.commit();*/
/**corrected code*/
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
toast("Map ready");
Log.d("--***** MAP ","::Map ready");
LatLng sydney = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
map.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
}
private void toast(String text){
Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
toast.show();
}
}
Run Code Online (Sandbox Code Playgroud)
location_map.xml文件
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
Com*_*are 74
据我所知,onMapReady()是通过将呼叫触发getMapAsync()你的MapFragment,我看不出你拨打的.
Abh*_*uri 11
要调用OnMapReady(GoogleMap map),请将以下内容附加到您的onCreate(...)方法:
MapFragment mapFragment = (MapFragment)
getFragmentManager().findFragmentById(R.id.map);
Run Code Online (Sandbox Code Playgroud)
然后加:
// This calls OnMapReady(..). (Asynchronously)
mapFragment.getMapAsync(MapDisplay.this);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38954 次 |
| 最近记录: |