Google maps can not resolve method getMap()
You should give a look to documentation
To add a map to an activity, add map fragment to your layout :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
And then use it in your activity :
public class MainActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
map.setMyLocationEnabled(true);
map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(final Marker marker) {....}
}
The map will be created in async way, and the onMapReady function will be called when map is ready,in this function you will be able to add markers, change position, title, zoom or whatever.
cannot find symbol method getMap()
private void setUpMapIfNeeded() {
if (mMap == null) {
SupportMapFragment mapFrag = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
mapFrag.getMapAsync(this);
if (mMap != null) {
setUpMap();
}
}
}
getMap()
is deprecated, use getMapAsync()
cannot resolve method getMap() : AppCompatActivity
Unable to find where the problem could. Let you try these lines.
If you implement the OnMapReadyCallback you need to override the onMapReady function.
public class GetLocationActivity extends AppCompatActivity implements OnMapReadyCallback {
GoogleMap gMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
....
...
.
gMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.gmap)).getMap();
..
..
}
@Override
public void onMapReady(GoogleMap googleMap) {
// your logic here
}
}
EDITED:
Remove these lines from your code. [ remove completely your second class]
Then make you first class to implement the onMapReadyCallback.
Then copy the necessary variables and logic to your first class itself.
// Remove below lines from your code.
public class AddPostActivity extends AddPostActivity implements OnMapReadyCallback {
private UiSettings mUiSettings;
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_post_activity);
MapFragment fm = (MapFragment) getFragmentManager().findFragmentById(R.id.maps_fragment);
fm.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mUiSettings = map.getUiSettings();
mUiSettings.setCompassEnabled(true);
mUiSettings.setMyLocationButtonEnabled(false);
}
}
Instead implement the same logic in your first class itself. Let me know for queries
Related Topics
Difference Between Google() and Maven { Url 'Https://Maven.Google.Com' }
Creating an Arraylist of Objects
Android and Getting a View with Id Cast as a String
How to Persist Permission in Android API 19 (Kitkat)
File Exists and Is Directory, But Listfiles() Returns Null
Calculating the Angle Between a Line and the X-Axis
Runtime.Exec():Reboot in Android
Android - Save Image from Url Onto Sd Card
Multiple Dex Files Define Landroid/Support/Annotation/Animres
Open Gallery App from Android Intent
Tcp\Ip Client - Ehostunreach (No Route to Host)
Httpurlconnection.Getresponsecode() Returns -1 on Second Invocation
Noclassdeffounderror on External Library Project for Android
Fatal Exception: Firebase-Messaging-Intent-Handle -- Java.Lang.Noclassdeffounderror
Does Proguard Work to Obfuscate Static String Constants
R.Raw.Anything Cannot Be Resolved
How to Encode String (Use Encrypt Messagedigest in Java) to Base64 String in Swift