-1

I'm new to android studio and i'm having a hard time implementing fragmented map. I have the Java code and xml but when run it on the emulator it keeps crashing. can any one help me figure out the issue.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
BB27
  • 1
  • 3
  • 2
    *`it keeps crashing.`* where is your code? where is the Crash report? have a look here **[Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this)** – AskNilesh Aug 30 '18 at 04:34
  • Please Share your code and error log over here. – Aditi Aug 30 '18 at 04:36

1 Answers1

0

Try this:

XML layout file

<fragment 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"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />

The maps activity Java file

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney, Australia, and move the camera.
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
 }
 }

Please follow all steps this link:

https://developers.google.com/maps/documentation/android-sdk/start

it helps you

Android Geek
  • 8,956
  • 2
  • 21
  • 35
  • Good answer overall . But try not to put all code so that people can just copy paste. This will only make them lazy. Except this let them put their code and answer should contain whats wrong and whats right . – ADM Aug 30 '18 at 05:11