In this Android Google Maps API Tutorial, we will create a simple map to save our favourite places in SQLite Database. So basically in this tutorial we will be creating an Android Location Manager to store our favorite places on map.
So lets begin our Android Google Maps Tutorial.
To use Google Maps we need Google Maps Android API. Now don’t worry about getting an API is very easy. First lets create our android project for this Android Google Maps Tutorial.
Android Google Maps Tutorial
- Open android studio and create a new Android Project.
- I named it GoogleMaps. Remember this time we will select Google Maps Activity from the predefined templates. (This will simplify the process of adding google map)

- Now click next -> and finish.
- You will see the below screen when your android google maps tutorial project is fully loaded.

- See the highlighted text it is a link. Copy this and paste it to your browser (Make sure you are logged in your google account). You will see this.

- Click on continue.

- Now click on Go to credentials.

- Now click on Create and you will get Your API Key.

- Now copy the API Key to your String inside google_maps_api.xml file. (From where you copied the link to create the api).
- Now run your application and you will that the app Start Google Maps (See the screenshot of my output).

- For this android google maps tutorial app we will create some buttons at the bottom of the map. For buttons I have used images, you can get the images from below. Paste the images inside your drawable folder.
- Now come inside activity_maps.xml and write the following xml code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <FrameLayout 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=".MapsActivity"> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="net.simplifiedcoding.mymapapp.MapsActivity" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="bottom" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#cc3b60a7" android:orientation="horizontal"> <ImageButton android:id="@+id/buttonCurrent" android:layout_width="50dp" android:layout_height="50dp" android:layout_margin="15dp" android:background="@drawable/current" /> <ImageButton android:id="@+id/buttonSave" android:layout_width="50dp" android:layout_height="50dp" android:layout_margin="15dp" android:background="@drawable/save" /> <ImageButton android:id="@+id/buttonView" android:layout_width="50dp" android:layout_height="50dp" android:layout_margin="15dp" android:background="@drawable/view" /> </LinearLayout> </LinearLayout> </FrameLayout> |
- This code would produce the following layout. This is the main layout of this android google maps tutorial. You can change the look if you want.

- We have created three buttons first one would be used to move to the current location, second will save a given location and the last one will be used for viewing the saved locations.
- Come inside MapsActivity.java.
- First we will implement the following interfaces.
1 2 3 4 5 6 7 8 9 | public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, GoogleMap.OnMarkerDragListener, GoogleMap.OnMapLongClickListener, View.OnClickListener{ |
- Now you will be seeing red lines, because we didn’t yet implemented the methods of the interfaces. So just put your cursor over red line and press alt+enter and click on implement methods (as shown in image).

- Now click ok and all the methods will be implemented.

- Now inside the class declare the following variables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, GoogleMap.OnMarkerDragListener, GoogleMap.OnMapLongClickListener, View.OnClickListener{ //Our Map private GoogleMap mMap; //To store longitude and latitude from map private double longitude; private double latitude; //Buttons private ImageButton buttonSave; private ImageButton buttonCurrent; private ImageButton buttonView; //Google ApiClient private GoogleApiClient googleApiClient; |
- Now write the following inside onCreate().
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); //Initializing googleapi client googleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); //Initializing views and adding onclick listeners buttonSave = (ImageButton) findViewById(R.id.buttonSave); buttonCurrent = (ImageButton) findViewById(R.id.buttonCurrent); buttonView = (ImageButton) findViewById(R.id.buttonView); buttonSave.setOnClickListener(this); buttonCurrent.setOnClickListener(this); buttonView.setOnClickListener(this); } |
- We need to override onStart() and onStop() to connect and disconnect to our Google Api Client. Write the following code to do this.
1 2 3 4 5 6 7 8 9 10 11 12 13 | @Override protected void onStart() { googleApiClient.connect(); super.onStart(); } @Override protected void onStop() { googleApiClient.disconnect(); super.onStop(); } |
- We will initialize our Map inside the overriden method onMapReady().
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @Override public void onMapReady(GoogleMap googleMap) { //Initializing our map mMap = googleMap; //Creating a random coordinate LatLng latLng = new LatLng(-34, 151); //Adding marker to that coordinate mMap.addMarker(new MarkerOptions().position(latLng).draggable(true)); mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); //Setting onMarkerDragListener to track the marker drag mMap.setOnMarkerDragListener(this); //Adding a long click listener to the map mMap.setOnMapLongClickListener(this); } |
- Now we will create two more methods one to get the current location getCurrentLocation() and other to move the map camera moveMap()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | //Getting current location private void getCurrentLocation() { //Creating a location object Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); if (location != null) { //Getting longitude and latitude longitude = location.getLongitude(); latitude = location.getLatitude(); //moving the map to location moveMap(); } } //Function to move the map private void moveMap() { //String to display current latitude and longitude String msg = latitude + ", "+longitude; //Creating a LatLng Object to store Coordinates LatLng latLng = new LatLng(latitude, longitude); //Adding marker to map mMap.addMarker(new MarkerOptions() .position(latLng) //setting position .draggable(true) //Making the marker draggable .title("Current Location")); //Adding a title //Moving the camera mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); //Animating the camera mMap.animateCamera(CameraUpdateFactory.zoomTo(15)); //Displaying current coordinates in toast Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); } |
- Come inside onConnected() method. This is also an overriden method, here we will call the getCurrentLocation() method.
1 2 3 4 5 6 | @Override public void onConnected(Bundle bundle) { getCurrentLocation(); } |
- When user will tap on the map for a long time we will add a marker at that position. We will also remove the previous marker. So come inside overriden method onMapLongClick().
1 2 3 4 5 6 7 8 9 10 11 12 | @Override public void onMapLongClick(LatLng latLng) { //Clearing all the markers mMap.clear(); //Adding a new marker to the current pressed position we are also making the draggable true mMap.addMarker(new MarkerOptions() .position(latLng) .draggable(true)); } |
- To get the coordinates after the drag we will use the overriden method onMarkerDragEnd(). Write the following code inside onMarkerDragEnd().
1 2 3 4 5 6 7 8 9 10 11 | @Override public void onMarkerDragEnd(Marker marker) { //Getting the coordinates latitude = marker.getPosition().latitude; longitude = marker.getPosition().longitude; //Moving the map moveMap(); } |
- Inside the onClick() method we will perform the button clicks. Write the following code inside onClick().
1 2 3 4 5 6 7 8 9 | @Override public void onClick(View v) { if(v == buttonCurrent){ getCurrentLocation(); moveMap(); } } |
- So far the full code we just created is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | package net.simplifiedcoding.googlemaps; import android.location.Location; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.LocationServices; 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.Marker; import com.google.android.gms.maps.model.MarkerOptions; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, GoogleMap.OnMarkerDragListener, GoogleMap.OnMapLongClickListener, View.OnClickListener{ //Our Map private GoogleMap mMap; //To store longitude and latitude from map private double longitude; private double latitude; //Buttons private ImageButton buttonSave; private ImageButton buttonCurrent; private ImageButton buttonView; //Google ApiClient private GoogleApiClient googleApiClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); //Initializing googleapi client googleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); //Initializing views and adding onclick listeners buttonSave = (ImageButton) findViewById(R.id.buttonSave); buttonCurrent = (ImageButton) findViewById(R.id.buttonCurrent); buttonView = (ImageButton) findViewById(R.id.buttonView); buttonSave.setOnClickListener(this); buttonCurrent.setOnClickListener(this); buttonView.setOnClickListener(this); } @Override protected void onStart() { googleApiClient.connect(); super.onStart(); } @Override protected void onStop() { googleApiClient.disconnect(); super.onStop(); } //Getting current location private void getCurrentLocation() { mMap.clear(); //Creating a location object Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); if (location != null) { //Getting longitude and latitude longitude = location.getLongitude(); latitude = location.getLatitude(); //moving the map to location moveMap(); } } //Function to move the map private void moveMap() { //String to display current latitude and longitude String msg = latitude + ", "+longitude; //Creating a LatLng Object to store Coordinates LatLng latLng = new LatLng(latitude, longitude); //Adding marker to map mMap.addMarker(new MarkerOptions() .position(latLng) //setting position .draggable(true) //Making the marker draggable .title("Current Location")); //Adding a title //Moving the camera mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); //Animating the camera mMap.animateCamera(CameraUpdateFactory.zoomTo(15)); //Displaying current coordinates in toast Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); } @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; LatLng latLng = new LatLng(-34, 151); mMap.addMarker(new MarkerOptions().position(latLng).draggable(true)); mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); mMap.setOnMarkerDragListener(this); mMap.setOnMapLongClickListener(this); } @Override public void onConnected(Bundle bundle) { getCurrentLocation(); } @Override public void onConnectionSuspended(int i) { } @Override public void onConnectionFailed(ConnectionResult connectionResult) { } @Override public void onMapLongClick(LatLng latLng) { //Clearing all the markers mMap.clear(); //Adding a new marker to the current pressed position mMap.addMarker(new MarkerOptions() .position(latLng) .draggable(true)); } @Override public void onMarkerDragStart(Marker marker) { } @Override public void onMarkerDrag(Marker marker) { } @Override public void onMarkerDragEnd(Marker marker) { //Getting the coordinates latitude = marker.getPosition().latitude; longitude = marker.getPosition().longitude; //Moving the map moveMap(); } @Override public void onClick(View v) { if(v == buttonCurrent){ getCurrentLocation(); moveMap(); } } } |
- We will also need the following permission to be added in our manifest.
1 2 3 4 5 | <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" /> |
- Now lets run this Android Google Maps Tutorial App. You will see the following output.
- If we will tap the first button (Only this button is working now). We will move the the current location.
- Bingo! Our Android Google Maps Tutorial is working fine. Though we have to code a bit more to fully complete our Android Locator.
- To drag the marker just long click over the marker and move your thumb to drag it. When you will press the first button it will again come to the current location. You can get my source code from my GitHub Repository from the link given below.
Get This Android Google Maps Tutorial Source from GitHub
[wp_ad_camp_1]
This Android Google Maps Tutorial is little long that is why I am breaking this part here in the next part we will add the functionality to remaining two button which is save and view.
So wait for the next part of Android Google Maps Tutorial or you can try completing it yourself. In the next part of our Android Google Maps Tutorial we will complete this app. Thank You 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.
thanks but can you show me how to create direction from my current location to destination point
how can i make this to calcuate the time and distance , like a taxi meter ?qa1`
I will post a tutorial for this ASAP (y)
can you provide full sourcecode for this tutorial,plz…..
Yeah I have given the link to github repository get it from there
when run 0.0.0.
why ??
I Have Error in LocationService
Hi when run app should have a dialog to ask for permission to turn on Location and also when I run the view is blank (only a Toast show current location)
Map loads from internet.. may be your internet is too slow?
no he is just using your API key which is why this is happening
he should use his own key then the map will be shown..
Hi this function
private void getCurrentLocation() {
mMap.clear();
//Creating a location object
Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
if (location != null) {
//Getting longitude and latitude
longitude = location.getLongitude();
latitude = location.getLatitude();
//moving the map to location
moveMap();
}
}
This function only get the last location (not the current one) we still need another function to listen to the location change and also function to update the location base on specific interval (As user moving, location of user change…)
Hi, I’m from Paraguay, I follow your tutorials, they are AMAZING! Please continue doing that. I have a question why doesn’t show me the map ?
Just show the coordinates of latitude and longitude,
have any idea?
check your API key 🙂
Hey Bro , Can you make a tutorial on how to track the current location , for example a car tracker.
Btw , AMAZING work and really helpful stuff.
Thanks
hello mr. i’m POST latitude and longtitude mysql and get mysql values maps
helpme
I want to show a marg on google map please help me how to show that Marg in map .
can u please mention where did u xplain about saving the favorite location to database??
very good tutorial, i wish you can make tutorial to save and reopen the location, more than one location, i am very appreciate if you can make that tutorial for all of us that waiting here
Hello Belal Khan: how do I get the coordinates of MySQL different places to put them on my map application? I appreciate all your help
Hey, This is very good. When I tried to use getCurrentLocation, It displays 0.0.0.0 location. and the whole map gets blank. Also can we have zoomin/zoomout functionality ?
Thanks! Good going !
on click of Current Location it is showing 0.0.0.0 in toast, please help me to resolve this
Try turning on the internet as well as the GPS and refresh it afterwards.
Hi bilal, i am nasir ali.
Can you post for Place autocomplete tutorial in android like this link
https://android-arsenal.com/details/1/2777
If you have any simple example demo to do this please inform me at nasiralityagi@gmail.com.
Hello Thankyou For the wonderful and very clear tutorial ..
But please can you help me whenever i click on current then in toast message show 0,0 longitude etc and my marker show just somewhere in sea ..
soo please kindly help me..
and one more thing i have a error on
Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
This line and they want to some permission error kindly please help..
Thank you so much for Great Tutorial
getMapAsync and .addApi(LocationServices.API) showing error Khan
mapFragment.getMapAsync(this);
//Initializing googleapi client
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build(); mapFragment.getMapAsync(this);
//Initializing googleapi client
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
getMapAsync and .addApi(LocationServices.API), @Override
public void onMapReady(GoogleMap googleMap) { showing error Khan
mapFragment.getMapAsync(this);
//Initializing googleapi client
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build(); mapFragment.getMapAsync(this);
//Initializing googleapi client
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
@Override
public void onMapReady(GoogleMap googleMap) {
thank u sir…
please help me
i want to search near by place
like ATM , hospital, bank, etc
Hello Mr,
Thanks a lot for all your great tutorials, i have a question about Maps activity,
i need to put some items (Buttons) for the Action Bar. I tried to add a toolbar using a separate xml file, changed the theme to Appcompat.no action bar, but no bar displayed. Can you please tell us how to add bar items to a Map Activity.
Thanks a lot.
How I can add image to the location
//Creating a LatLng Object to store Coordinates
LatLng latLng = new LatLng(latitude, longitude);
Here I get Location. I want to add image to that location and also description of that location
hello I want add multiple marker in this map and data is coming from the server mean we do not final any array or data .
Great tutorial, thank you!!
One qustion’s pls
Is there any way to get current user location right away on Activity start (onMapReady), and show it right away with marker?
and some how, when i played with the markers inside the method, i got my accuracy much more presice, on the default it was like 100 meters away from me…. Weird.
Any way, like said before great tutorial, and any help would be appriciated!!
Is the next part out? If not, when is it coming?
please i need your help on this so if you have sample kindly give me the the link for the source code. i want to determine a walking distance of user from current location to new location in meters using the android google map.i want to use the app to plant trees in a distance of 5 meters. here the device current location is the starting point to place the first tree and when the user walk to a distance of 5 meters the marker should pop up to place the next tree.
This is my idea i need you friends to help me implement it.i hope to here from you @Khan.
https://github.com/probelalkhan/android-google-maps-tutorial-part1
Download Source code from here
Hello Belal,
Thank you for the amazing tutorial
I have a query and it is kind of urgent. I want to know how to make the toolbar option which contains the searchview work for searching places in google map. I know to use a button and then code for it, but in toolbar the searchview has the magnifying glass symbol , how do i integrate it with the google map and use geocode.
This is the code I want to implement:
private void doSearch() {
EditText location_field = (EditText) findViewById(R.id.edtsearch);
String location = location_field.getText().toString();
List addressList = null;
if (location != null || !location.equals(“”)) ;
{
Geocoder geocoder = new Geocoder(this);
{
try {
addressList = geocoder.getFromLocationName(location, 1);
} catch (IOException e) {
e.printStackTrace();
}
Address address = addressList.get(0);
LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title(“Marker”));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.getUiSettings().isCompassEnabled();
mMap.getUiSettings().isZoomControlsEnabled();
}
did u got the solution??? if yes please do share me ur code
patilshashi43@gmail.com
Hey nice tutorials
Doing great for the beginners
Can i get to know how can i show the direction on the map ( Turn by Turn navigation )
I want turn to turn navigation facility.
I couldn’t find any solution for that
Thank you
how can i make this save and view
Nice Tutorial But Location Was Not Update Until In build Map location was Not Updated.Every Time For Location Update I Need To Open Google Map.After Location Update In Google Map It Will Show On My Map .
Thanks for this tutorial. when you post part 2 of this tutorial?
Hi, I wanted to know if the tutorial for Save and View functionality is out. Thank you!
Thanks for the great tutorial , I couldn’t get latitude and longitude of the location it’s showing 0.0.0.0,0.0.0.0though I enabled gps and Internet on my phone .
Thanks,
Harshitha
Hello,
I need your help i want to implement google map to pick a place when moving on map can u please give me any hint! How can i implement it
nice tutorial ..
whens gonna next part be released??
Great tutorial, will you post a next part?
Hi, thanks for the tutorial has guided me, I have the NEXT certainly I would like to have a map which call data from a mysql and that when selecting a marker I send to the activity of the marker, you help me thanks.
public class MapGeneral extends FragmentActivity implements GoogleMap.OnMyLocationChangeListener {
private GoogleMap googleMap;
private HashMap idmarker = new HashMap();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mapa_general);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
ArrayList<WeakHashMap> location = null;
String url = “http://www.lifes.com.co/vet_life/info_map_general.php”;
try {
JSONArray data = new JSONArray(getHttpGet(url));
location = new ArrayList();
WeakHashMap map;
for (int i = 0; i < data.length(); i++) {
JSONObject market = data.getJSONObject(i);
map = new HashMap();
map.put(“ID”, String.valueOf(market .getInt(“ID”)));
map.put(“lat”, market .getString(“lat”));
map.put(“lng”, market .getString(“lng”));
map.put(“name”, market .getString(“name”));
map.put(“description”, market .getString(“description”));
location.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
assert location != null;
Double latitude = Double.parseDouble(location.get(0).get(“lat”));
Double longitude = Double.parseDouble(location.get(0).get(“lng”));
LatLng coordinate = new LatLng(latitude, longitude);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setMyLocationEnabled(true);
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinate, 24));
if (ActivityCompat.checkSelfPermission(getApplicationContext(),
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
return;
}
Marker markers = null;
for (int i = 0; i < location.size(); i++) {
latitude = Double.parseDouble(location.get(i).get("lat"));
longitude = Double.parseDouble(location.get(i).get("lng"));
String name = location.get(i).get("name");
String descip = location.get(i).get("description");
MarkerOptions markerOptions = new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(name)
.snippet(descip);
markers = googleMap.addMarker(markerOptions);
googleMap.setOnMyLocationChangeListener(this);
markers.showInfoWindow();
idmarker.put(markers, i);
}
googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent gotomarket = new Intent(getApplicationContext(), Info.class);
LatLng lat_long = marker.getPosition();
int id = idmarker.get(marker);
gotomarket .putExtra("tienId", id);
gotomarket .putExtra("lat", lat_long.latitude);
gotomarket .putExtra("long", lat_long.longitude);
startActivity(gotomarket );
}
});
}
@Override
public void onMyLocationChange(Location loc) {
LatLng myposicion = new LatLng(loc.getLatitude(), loc.getLongitude());
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myposicion, 14));
googleMap.setOnMyLocationChangeListener(null);
}
public static String getHttpGet(String url) {
StringBuilder str = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) { // Download OK
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
str.append(line);
}
} else {
Log.e("Log", "Failed to download result..");
}
} catch (IOException e) {
e.printStackTrace();
}
return str.toString();
}
}
Can you please share php file and .sql file?
Getting my current location but current location is not displayed on map…Its appearing blank.
Please help me
plz send me the code for store the latitude and longitude value in mysql database…..
plz help me…..
whenever u get the lat and long call api
After i run the app when i click on currect location button it’s showing a toast 0.0,0.0,
why?
and also the save and folder not working as well .
thank you
Hello please help me in this,
it display error in LocationServices that cant find Symbol LocationServices services,
i cant understand what is use of this
Please send me code for save and view currently . I try make code myself but it not working well . Anyone please help me ??
Thank you .
//Creating a location object
Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
Android check permission for LocationManager???
where is the second part please?
LocationServices got error plz bro help us
How can I get locations from a Mysql database and display them on a android app showing a marker on the map?
I have a custom Google map that currently gets the locations from an array or javascript variable named locations. I want the data to no longer be enter manually, but to be inserted dynamically from a database. How can I go about achieving this? I am using the Google map Api.
Thanks in advance
how do I get the coordinates of MySQL different places to put them on my map application?