Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import com.google.android.gms.maps.model.LatLng in Android Studio

I am trying to create a new class in an Android project but keep getting the following error:

error: package com.google.android.gms.maps.model does not exist

I have installed Google Play Services in the SDK manager. Any idea how to fix this?

Android dev noob here

like image 968
zoran119 Avatar asked Jan 15 '14 10:01

zoran119


2 Answers

Add this to your gradle file

compile "com.google.android.gms:play-services-maps:10.0.1"
like image 140
sanevys Avatar answered Oct 02 '22 01:10

sanevys


For me, I started by discovering that upgrading my gradle was not going as planned, as I was importing from jcenter, which apparently only goes up to 2.3. I modified my buildscript by adding google() to my build.gradle as follows:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
    }
}

Next I found that it was importing com.google.android.gms multiple times, so when it told me that "compile" was obsolete, I had to change everything to either "implementation" or "api". For the maps and location services I used "api", in order to avoid the duplication errors, and that fixed it for me without changing the play services number.

dependencies {
    api 'com.google.android.gms:play-services-location:9.6.1'
    api 'com.google.android.gms:play-services-maps:9.6.1'
}
like image 21
Arthulia Avatar answered Oct 02 '22 01:10

Arthulia