Download Code

Android Retrieve Coordinates Mysql Map

In android retrieve coordinates mysql map tutorial you will learn how to retrieve location coordinates from mysql database and plot on Google Map.You will JSON Parser and HTTP Components to get the coordinates.

You must go through these tutorials before starting this tutorial.

Server End

  • Start XAMPP Server and go to “localhost/phpmyAdmin”.
  • Create new database “codeclogin”.
  • Create new table “societylocations”.

Google map,google map in android,map in android,latitude,longitude, SupportMapFragment,SupportMapFragment in xml,SupportMapFragment in android, how to use SupportMapFragment in google map android, http client,httpclient in android,httpget,httpresponse,JSON, how to parse JSON coordinates in android, how to retrieve coordinates from database in android, how to retrieve coordinates from database and plot on map, how to retrieve coordinates from database and plot on map in android, how to retrieve coordinates from database and plot on map android tutorial, how to load co-ordinates from mysql to android tutorial, how to load co-ordinates from mysql to android source code, how to load co-ordinates from mysql to android,addMarker,moveCamera,android retrieve coordinates mysql map,

Find the PHP API File under Coordinates directory.Put it in XAMPP > htdocs.

Create new android application project.Go to activity_main.xml file and add Fragment with SupportMapFragment class.

Google map,google map in android,map in android,latitude,longitude, SupportMapFragment,SupportMapFragment in xml,SupportMapFragment in android, how to use SupportMapFragment in google map android, http client,httpclient in android,httpget,httpresponse,JSON, how to parse JSON coordinates in android, how to retrieve coordinates from database in android, how to retrieve coordinates from database and plot on map, how to retrieve coordinates from database and plot on map in android, how to retrieve coordinates from database and plot on map android tutorial, how to load co-ordinates from mysql to android tutorial, how to load co-ordinates from mysql to android source code, how to load co-ordinates from mysql to android,addMarker,moveCamera,,android retrieve coordinates mysql map,

Next MainActivity.java.Do the following Steps.

  • Create Google Map class variable.
  • Refer Fragment from XML.
  • Perform HTTP_GET request to get co-ordinates.
  • Parse JSON String with JSON Array and JSON Object.
  • Then pass values of latitude and longitude to addMarker method.
  • Finallay animate camera to particular location.
package developer.codecmap;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;

import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;


public class MainActivity extends FragmentActivity {
	GoogleMap googleMap;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		StrictMode.setThreadPolicy(policy);
		// Getting reference to the SupportMapFragment of activity_main.xml
		SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

		// Getting GoogleMap object from the fragment
		googleMap = fm.getMap();

		// Enabling MyLocation Layer of Google Map
		googleMap.setMyLocationEnabled(true);
		String data;
		try {
			DefaultHttpClient client = new DefaultHttpClient();
			HttpGet request = new HttpGet("http://your_server_ip/Coordinates/locations.php");
			HttpResponse response = client.execute(request);
			HttpEntity entity=response.getEntity();
			data=EntityUtils.toString(entity);
			Log.e("STRING", data);
			try {

				JSONArray json=new JSONArray(data);
				for(int i=0;i<json.length(); i++)
				{
					JSONObject obj=json.getJSONObject(i);
					String lati=obj.getString("latitude");
					String longi = obj.getString("longitude");
					/*lat.add(lati);
					log.add(longi);*/

					googleMap.addMarker(new MarkerOptions()
					.position(new LatLng(Double.valueOf(lati),Double.valueOf(longi)))
					.title(Double.valueOf(lati).toString() + "," +Double.valueOf(longi).toString()));
					
					Log.e("locations", Double.valueOf(lati).toString());




				}

			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		} catch (ClientProtocolException e) {
			Log.d("HTTPCLIENT", e.getLocalizedMessage());
		} catch (IOException e) {
			Log.d("HTTPCLIENT", e.getLocalizedMessage());
		}
		googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(33.562031,73.071249),15.0f));
	}
}

Your Android Manifest.xml file should be like this.

Google map,google map in android,map in android,latitude,longitude, SupportMapFragment,SupportMapFragment in xml,SupportMapFragment in android, how to use SupportMapFragment in google map android, http client,httpclient in android,httpget,httpresponse,JSON, how to parse JSON coordinates in android, how to retrieve coordinates from database in android, how to retrieve coordinates from database and plot on map, how to retrieve coordinates from database and plot on map in android, how to retrieve coordinates from database and plot on map android tutorial, how to load co-ordinates from mysql to android tutorial, how to load co-ordinates from mysql to android source code, how to load co-ordinates from mysql to android,addMarker,moveCamera,android retrieve coordinates mysql map,

Run your android application project.

Google map,google map in android,map in android,latitude,longitude, SupportMapFragment,SupportMapFragment in xml,SupportMapFragment in android, how to use SupportMapFragment in google map android, http client,httpclient in android,httpget,httpresponse,JSON, how to parse JSON coordinates in android, how to retrieve coordinates from database in android, how to retrieve coordinates from database and plot on map, how to retrieve coordinates from database and plot on map in android, how to retrieve coordinates from database and plot on map android tutorial, how to load co-ordinates from mysql to android tutorial, how to load co-ordinates from mysql to android source code, how to load co-ordinates from mysql to android,addMarker,moveCamera,android retrieve coordinates mysql map,

That’s it for this tutorial.

Thanks.