在 Android 应用中设置 GoogleMap
Setting up GoogleMap in Android app
我正在尝试将 googlemap 添加到我的应用程序中,但无法正常工作。
顺便说一句,我正在 xamarin 上使用 ViewPager。
布局:
...
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.maps.MapFragment" />
...
我的片段:
public class InfoFragment : FragmentV4, IOnMapReadyCallback
{
private GoogleMap mMap;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(Resource.Layout.InfoFragment, container, false);
//Set up google maps coords in infos section
SetUpMap();
return view;
}
private void SetUpMap()
{
if (mMap == null) {
//((MapFragment)FragmentManager.FindFragmentById (Resource.Id.map)).GetMapAsync (this);
var mapFragment = (SupportMapFragment)Activity.SupportFragmentManager.FindFragmentById(Resource.Id.map);
mapFragment.GetMapAsync(this);
}
}
//Launching of the actual map
public void OnMapReady (GoogleMap googleMap)
{
//Setup cords and stuff...
}
}
在我的地图设置过程中。当我做
var mapFragment = (SupportMapFragment)Activity.SupportFragmentManager.FindFragmentById(Resource.Id.map);
它始终 returns 为空。有人可以帮忙吗?
找到问题
android:name="com.google.android.gms.maps.MapFragment" />
应该是:
android:name="com.google.android.gms.maps.SupportMapFragment" />
在我的片段中而不是:
var mapFragment = (SupportMapFragment)Activity.SupportFragmentManager.FindFragmentById(Resource.Id.map);
mapFragment.GetMapAsync(this);
应该是:
((SupportMapFragment)ChildFragmentManager.FindFragmentById(Resource.Id.map)).GetMapAsync(this);
我正在尝试将 googlemap 添加到我的应用程序中,但无法正常工作。 顺便说一句,我正在 xamarin 上使用 ViewPager。 布局:
...
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.maps.MapFragment" />
...
我的片段:
public class InfoFragment : FragmentV4, IOnMapReadyCallback
{
private GoogleMap mMap;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(Resource.Layout.InfoFragment, container, false);
//Set up google maps coords in infos section
SetUpMap();
return view;
}
private void SetUpMap()
{
if (mMap == null) {
//((MapFragment)FragmentManager.FindFragmentById (Resource.Id.map)).GetMapAsync (this);
var mapFragment = (SupportMapFragment)Activity.SupportFragmentManager.FindFragmentById(Resource.Id.map);
mapFragment.GetMapAsync(this);
}
}
//Launching of the actual map
public void OnMapReady (GoogleMap googleMap)
{
//Setup cords and stuff...
}
}
在我的地图设置过程中。当我做
var mapFragment = (SupportMapFragment)Activity.SupportFragmentManager.FindFragmentById(Resource.Id.map);
它始终 returns 为空。有人可以帮忙吗?
找到问题
android:name="com.google.android.gms.maps.MapFragment" />
应该是:
android:name="com.google.android.gms.maps.SupportMapFragment" />
在我的片段中而不是:
var mapFragment = (SupportMapFragment)Activity.SupportFragmentManager.FindFragmentById(Resource.Id.map);
mapFragment.GetMapAsync(this);
应该是:
((SupportMapFragment)ChildFragmentManager.FindFragmentById(Resource.Id.map)).GetMapAsync(this);