Reputation: 541
I have a navigation drawer with fragments for each page. And in one of my fragments i want to display a mapview. But not in full screen, i want it to be like the top half of screen and below that i will give some contact information for a specific coordinate. I tried too many tutorial but i couldn't get this working.
The Page XML which Map is supposed to be displayed
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/map_background"
tools:context="com.corvega.ztbb.IletisimFragment">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ContactMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>
Behind the Map's page JAVA
public class IletisimFragment extends Fragment {
public MapView mapView;
private static GoogleMap googleMap;
public IletisimFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_iletisim, container, false);
if (googleMap != null)
setUpMap();
if (googleMap == null)
{
googleMap = ((MapFragment)MainActivity.fragmentManager.findFragmentById(R.id.ContactMapView)).getMap();
if (googleMap != null)
{
setUpMap();
}
}
return rootView;
}
private static void setUpMap()
{
googleMap.setMyLocationEnabled(true);
googleMap.addMarker(new MarkerOptions().position(new LatLng(41.009471, 28.916134)).title("baslik"));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(41.009471, 28.916134), 12.0f));
}
@Override
public void onDestroyView()
{
super.onDestroyView();
if (googleMap != null)
{
MainActivity.fragmentManager.beginTransaction()
.remove(MainActivity.fragmentManager.findFragmentById(R.id.ContactMapView))
.commit();
googleMap = null;
}
}
}
My AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:name="com.arshad.map.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_icon_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" />
<activity
android:name=".SplashScreen"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_icon_name"
android:noHistory="true"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter android:label="@string/app_icon_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my api key was here"/>
</application>
</manifest>
dependencies in Build.Gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.android.gms:play-services:5.2.08'
}
However my final result is this. I am sure that Google Play Services is up-to date on the phone. So do you have any suggestions?
Upvotes: 0
Views: 2789
Reputation: 1954
Change your gradle file to
compile 'com.google.android.gms:play-services:5.0.89'
unless if you're targeting L Preview
Upvotes: 1