使用.GetMapAsync代替.getMap方法与Google Play服务(Xamarin) [英] Use .GetMapAsync instead .getMap method with Google Play Services (Xamarin)
问题描述
LatLng location = new LatLng(myClass.myLocation.Latitude,myClass。 myLocation.Longitude);
CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
builder.Target(location);
builder.Zoom(18);
CameraPosition cameraPosition = builder.Build();
MapsInitializer.Initialize(this);
CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
MapFragment googleMap = FragmentManager.FindFragmentById< MapFragment> (Resource.Id.map);
theMap = googleMap.Map;
if(theMap!= null){
theMap.MapType = GoogleMap.MapTypeNormal;
theMap.MoveCamera(cameraUpdate);
}
但现在 .Map
已过时并且不推荐使用,我必须以某种方式使用 .GetMapAsync
:
theMap = googleMap.GetMapAsync(IOnMapReadyCallback);
但我不明白。
<有人可以帮我吗? 你的地图片段类必须实现
OnMapReadyCallback code>并覆盖 onMapReady()
: @Override
public void onMapReady(最终GoogleMap地图){
this.map = map;
map.setMyLocationEnabled(true);
$ / code>
在您的 onCreateView
使用 getMapAsync()
设置片段上的回调:
MapFragment mapFragment =(MapFragment)getFragmentManager()
.findFragmentById(R.id.map); mapFragment.getMapAsync(本);
实现google maps V2所需的全部内容如下:
https://developers.google.com/maps/documentation/android/map
An old code works perfectly in this way:
LatLng location = new LatLng (myClass.myLocation.Latitude, myClass.myLocation.Longitude);
CameraPosition.Builder builder = CameraPosition.InvokeBuilder ();
builder.Target (location);
builder.Zoom (18);
CameraPosition cameraPosition = builder.Build ();
MapsInitializer.Initialize (this);
CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition (cameraPosition);
MapFragment googleMap = FragmentManager.FindFragmentById<MapFragment> (Resource.Id.map);
theMap = googleMap.Map;
if (theMap != null) {
theMap.MapType = GoogleMap.MapTypeNormal;
theMap.MoveCamera (cameraUpdate);
}
but now that the .Map
is obsolete and deprecated, I must to use .GetMapAsync
in some way:
theMap = googleMap.GetMapAsync (IOnMapReadyCallback);
But I don't understand how.
There is somebody that can help me?
解决方案 Your map fragment class must implement OnMapReadyCallback
and override onMapReady()
:
@Override
public void onMapReady(final GoogleMap map) {
this.map = map;
map.setMyLocationEnabled(true);
}
In your onCreateView
use getMapAsync()
to set the callback on the fragment:
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map); mapFragment.getMapAsync(this);
All that you need to implement the google maps V2 is here:
https://developers.google.com/maps/documentation/android/map
这篇关于使用.GetMapAsync代替.getMap方法与Google Play服务(Xamarin)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!