-1

I have looked through about 10 stackoverflow pages on this topic and none of the solutions are helping me. I have copied the code from the first answer in this post, but I am still getting a lot of errors. What I want is to create the map in a class called MapFragment, and then display it in a tab of an app.

As of now here is my code: Java:

public class MapFragment extends Fragment {
    private static final String ARG_SECTION_NUMBER = "section_number";
    private final LatLng HAMBURG = new LatLng(53.558, 9.927);   //Error: cannot resolve symbol 'LatLng'
    private final LatLng KIEL = new LatLng(53.551, 9.993);      //Error: cannot resolve symbol'LatLng'
    private GoogleMap map;                    //Error: cannot resolve symbol GoogleMap

    public MapFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View rootView = inflater.inflate(R.layout.fragment_map, container, false);

        map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();      //Error:cannot resolve symbol 'SupportMapFragment'

        Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
                .title("Hamburg"));                          //Error:cannot resolve symbol 'Marker' or 'MarkerOptions' or method 'addMarker'
        Marker kiel = map.addMarker(new MarkerOptions()      //Error:cannot resolve symbol 'Marker' or 'MarkerOptions' or method 'addMarker'
                .position(KIEL)
                .title("Kiel")
                .snippet("Kiel is cool")
                .icon(BitmapDescriptorFactory
                .fromResource(R.drawable.ic_launcher)));

        // Move the camera instantly to hamburg with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));    //Error:cannot resolve symbol 'CameraUpdateFactory' or method 'moveCamera'

        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);//Error:cannot resolve symbol 'CameraUpdateFactory' or method 'animateCamera'

        //...

        return rootView;
    }
}

XML:

<?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="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

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

</RelativeLayout>

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="example.mapapp" >

    <permission
        android:name="com.example.lastgmap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.lastgmap.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="MY_API_KEY" />

    </application>

</manifest>

my dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services:7.5.0'
}

I do not understand what is going on. Is there some import I am missing class I need to cut and paste to make this work? On a diferent tutorial they had me import this

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

but on both lines I get an error cannot resolve symbol 'android'.

I am currently using android studio. The API key is entered in my actual compute I just left it out from the stack overflow post.

Community
  • 1
  • 1
JohnF
  • 23
  • 8

2 Answers2

1

Below steps for taking care when we are working with Google map.

Make sure you have added Google Play Services Library as Library project.

If you are sure for above step and still problem is not resolved than please update your Google Play Service Library by SDK Manager.

If you have updated library and still problem is not resolved than please do Clean and ReBuild project.

If you have performed above step and still problem is not resolved than please restart your Eclipse, sometime magically it works.

Hope it will help you.

Hiren Patel
  • 52,124
  • 21
  • 173
  • 151
  • Do you know how I would add Google Play Services Library in android studio? – JohnF Jul 02 '15 at 16:08
  • @AlecS, you have to do right click on project property - > then choose second Android tab. please refer http://stackoverflow.com/questions/26457096/appcompat-v7-r21-returning-error-in-values-xml/29666124#29666124 and right hand side you can check add option. Select it, add your library project -> click apply - >click ok. – Hiren Patel Jul 02 '15 at 16:16
  • [This](http://imgur.com/u7ghBlt) is what I am seeing. Where is the project property tab? – JohnF Jul 02 '15 at 16:29
  • @AlecS, If you are using eclipse then right click on project then select last option property – Hiren Patel Jul 02 '15 at 16:33
  • @AlecS, if you are using android studio then click on file - > Project structure - > then go to last option - > Dependencies ->click on + button -> then select library dependeny - > search google play service library. – Hiren Patel Jul 02 '15 at 16:36
  • searching for google play service library yields nothing. `com.google.android.gms:play-sercives:7.5.0` was already there. I am still getting my errors though. – JohnF Jul 02 '15 at 17:00
0

You need to add more detail in your question. - Do you use Android Studio or Eclipse? - Did you add your key of google map into your manifest or not. - If use Android Studio did you add dependency of google play service into your gradle build file? May be it because you forgot to add dependency so the compiler cannot find your class

Nam
  • 56
  • 1
  • 7
  • I am currently using android studio. The API key is entered in my actual compute I just left it out from the stack overflow post. I have posted my dependencies above. – JohnF Jul 02 '15 at 16:14
  • Can you give me more detail of your error? Above, you just give me two error with the import. – Nam Jul 02 '15 at 16:30