【发布时间】:2018-04-20 01:10:42
【问题描述】:
这是我的代码, 我正在尝试向谷歌地图添加书签,并在特定位置初始化地图,但我不明白 SupporMapFragment 是如何工作的,如果有人可以帮助我解释如何做到这一点,谢谢
internal class DetailMapFragment : BaseFragment , IOnMapReadyCallback
{
private GoogleMap GoogleMap;
private SupportMapFragment _mapFragment;
public override int LayoutId => Resource.Layout.map_page;
protected override void InitViews()
{
//var mapView = mView.FindViewById<MapView>(Resource.Id.mapView);
//mapView.GetMapAsync(this);
try
{
_mapFragment = Activity.SupportFragmentManager.FindFragmentByTag("map") as SupportMapFragment;
if (_mapFragment == null)
{
GoogleMapOptions mapOptions = new GoogleMapOptions()
.InvokeMapType(GoogleMap.MapTypeNormal)
.InvokeZoomControlsEnabled(false)
.InvokeMaxZoomPreference(20)
.InvokeCompassEnabled(true);
FragmentTransaction fragTx = FragmentManager.BeginTransaction();
_mapFragment = SupportMapFragment.NewInstance(mapOptions);
fragTx.Add(Resource.Id.mapView, _mapFragment, "map");
fragTx.Commit();
LatLng latlong = new LatLng(40.776408,-73.970755);
MarkerOptions mark = new MarkerOptions()
.SetPosition(latlong)
.SetTitle("New York")
.SetSnippet("Apple");
_mapFragment.AddMarker(mark);
}
_mapFragment.GetMapAsync(this);
}
catch (System.Exception ex)
{
ex.Message.ToString();
}
public void OnMapReady(GoogleMap googleMap)
{
//this.GoogleMap = googleMap;
}
void IOnMapReadyCallback.OnMapReady(GoogleMap googleMap)
{
//try
//{
// this.GoogleMap = googleMap;
// if (googleMap != null)
// {
// googleMap.AnimateCamera(CameraUpdateFactory.NewLatLng(new LatLng(-11.083271, -76.207374)));
// }
//}
//catch (System.Exception ex)
//{
// ex.Message.ToString();
//}
}
}
我是 xamarin android 的新手,我无法理解如何将 de 标记添加到地图
【问题讨论】:
-
我不明白您将地图加载到特定位置是什么意思。
标签: xamarin.android google-maps-markers supportmapfragment