Can't Create Project With Google Map Android Api V2
I have read document in https://developers.google.com/maps/documentation/android/start I create project android in eclipse, folow document step by step but when I can't run projec
Solution 1:
First of all you need to change your Activity
to FragmentActivity
while extending in your class as below:
publicclassMainActivityextendsFragmentActivity{
And also your layout inflating which contains the GoogleMap
view is having name Fragment_main
and in your activity you have inflated the layout activity_main
which is wrong.
So change your setContentView
layout
setContentView(R.layout.activity_main);
to
setContentView(R.layout.Fragment_main);
Also as you are having the minimum api level below 11 so you have to use SupportMapFragment
to load the map as below:
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
EDITED:
In your manifest change your below line
<meta-data
android:name="com.google.android.gms.version"
android:value="15" />
to
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Also change your Fragment
class name as below in your fragment_main
layout file.
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Solution 2:
you need to extends your class a FragmentActivity instead of Activity.
Other thing that you have to add
<uses-featureandroid:glEsVersion="0x00020000"android:required="true" />
in your manifest file.
Also change this
if(map!=null){
LatLng sydney = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
map.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
}
UPDATE:
change here from
setContentView(R.layout.activity_main);
to
setContentView(R.layout.Fragment_main);
Use this
<FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/container"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.mrbuoi.bactai_app.MainActivity"tools:ignore="MergeRootFrame" ><includelayout="@layout/Fragment_main"></include></FrameLayout>
Post a Comment for "Can't Create Project With Google Map Android Api V2"