我尝试在我的应用中显示Google地图,但似乎我的地图未显示正确位置,如下
这是我的代码:
public class Frag_Contact extends Fragment implements OnMapReadyCallback {
SupportMapFragment mMapFragment;
LatLng MAP_MAIN = new LatLng(1.254337, 103.823776);
View rootView;
public Frag_Contact(){
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
((MainActivity) getActivity()). custom_searchbox();
rootView = inflater.inflate(R.layout.fragment_contact, container, false);
mMapFragment = ((SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map_kantor));
mMapFragment.getMapAsync(this);
return rootView;
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onDestroyView() {
super.onDestroyView();
Fragment fragment = (getChildFragmentManager().findFragmentById(R.id.map_kantor));
getActivity().getSupportFragmentManager().beginTransaction().remove(fragment).commit();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onDetach() {
super.onDetach();
}
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setMyLocationEnabled(true);
googleMap.addMarker(new MarkerOptions().position(MAP_MAIN).title("SINARMAS"));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(MAP_MAIN, 15));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(0), 2000, null);
}
}
这是我的布局:
<LinearLayout
android:id="@+id/child_home"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="30dp"
android:orientation="vertical">
<fragment
android:id="@+id/map_kantor"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_margin="10dp"
android:name="com.google.android.gms.maps.SupportMapFragment" />
这是我的清单:
<permission
android:name="id.co.application.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="id.co.ajsmsig.e_sehat.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyMaterialTheme" >
<activity
android:name=".activity.Splash"
android:screenOrientation="portrait"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation"
android:noHistory="true"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/api" />
</application>
似乎我的地图没有显示我想要的正确位置,并且我的应用程序中的地图没有显示完整的地图,如上所示,它只是我应用程序中显示的地图的一半,我希望有人明白我的想法并帮我解决我的问题。非常感谢你。