Simple android program using GOOGLE MAP API

前端 未结 2 1312
故里飘歌
故里飘歌 2021-01-28 10:03

Trying to work on Google Map\'s

  • Its my first program in using google Map API
  • I am not able to execute because of log error
  • Where i need to corr
相关标签:
2条回答
  • 2021-01-28 10:55

    Just follow The Links As its your first map application.

    http://mobiforge.com/developing/story/developing-with-google-maps-v2-android Follow the link and check 1)make Sure U have google map v2 support library (Add android-support-v4) and

    public class MainActivity extends FragmentActivity {
    

    2)Check and modify the Manifest 3) In layout

    <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/crntlocation"
            class="com.google.android.gms.maps.SupportMapFragment" />
    

    4) In Activity

    SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                        .findFragmentById(R.id.map);
                googleMap = fm.getMap();
    

    It will solve your Problem.

    0 讨论(0)
  • 2021-01-28 11:00

    You have to declare fragment class of map in your xml layout as below: Which is used to load the GoogleMap in your fragment.

    Have your referred Add a Map in your Application ?

    <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    

    EDITED:

    The error is because your application contains the API level below 12 . And Please note that the code below is only useful for testing your settings in an application targeting Android API 12 or later, Below code should not be used in a production application.

          googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    

    So instead try as below:

       mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
    
    0 讨论(0)
提交回复
热议问题