Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:38:18+00:00 2026-06-07T04:38:18+00:00

I have a google map inside my android application which have a simple hardcoded

  • 0

I have a google map inside my android application which have a simple hardcoded marker on it.I have some saved data in mysql db with latitude and longitude and i want to read that data from mysql db and then displaying this on my google map in android.I mean how can i make map from my mysql db data.here is my code for loading map having simple hardcoded marker.

Update

 package com.javacodegeeks.android.googlemaps;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

//import android.app.ListActivity;
import android.net.ParseException;
//import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;



public class GMapsActivity extends MapActivity {

private MapView mapView;

JSONArray jArray;
String result = null;
InputStream is = null;
StringBuilder sb=null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mapView = (MapView) findViewById(R.id.map_view);       
        mapView.setBuiltInZoomControls(true);

 ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//http post
try{
     HttpClient httpclient = new DefaultHttpClient();
     HttpPost httppost = new HttpPost("http://sml.com.pk/a/map.php");
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     HttpResponse response = httpclient.execute(httppost);
     HttpEntity entity = response.getEntity();
     is = entity.getContent();
     }catch(Exception e){
         Log.e("log_tag", "Error in http connection"+e.toString());
    }
//convert response to string
try{
      BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
       sb = new StringBuilder();
       sb.append(reader.readLine() + "\n");

       String line="0";
       while ((line = reader.readLine()) != null) {
                      sb.append(line + "\n");
        }
        is.close();
        result=sb.toString();
        }catch(Exception e){
              Log.e("log_tag", "Error converting result "+e.toString());
        }
//paring data
double LAT;
double LANG;
String INFO;
try{
      jArray = new JSONArray(result);
      JSONObject json_data=null;
      for(int i=0;i<jArray.length();i++){
             json_data = jArray.getJSONObject(i);
             LAT=json_data.getDouble("LAT");
             LANG=json_data.getDouble("LANG");
             INFO=json_data.getString("INFO");


//Overlay code
List<Overlay> mapOverlays = mapView.getOverlays();
                Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
        CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);

        //GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
        GeoPoint point = new GeoPoint((int)(LAT * 1e6),(int)(LANG * 1e6));
        OverlayItem overlayitem = new OverlayItem(point, "", INFO);
        itemizedOverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedOverlay);

        MapController mapController = mapView.getController();

        mapController.animateTo(point);
        mapController.setZoom(6);

//Overlay code

         }
      }
      catch(JSONException e1){
          Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
      } catch (ParseException e1) {
            e1.printStackTrace();
    }
}
@Override
protected boolean isRouteDisplayed() {
    return false;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:38:20+00:00Added an answer on June 7, 2026 at 4:38 am

    you can do this

    ArrayList<Data> dynamicData=getData();
        if(dynamicData!=null)
        {
            for(int i=0;i<dynamicData.size();i++)
            {
                Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
                CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
    
                //GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
                GeoPoint point = new GeoPoint((int)(Double.parseDouble(dynamicData.get(i).lat) * 1e6),(int)(Double.parseDouble(dynamicData.get(i).lon) * 1e6));
                OverlayItem overlayitem = new OverlayItem(point, "SML", "Shakarganj Mills Limited Jhang");
    
                itemizedOverlay.addOverlay(overlayitem);
                mapOverlays.add(itemizedOverlay);
            }
        }
    

    and

    public static ArrayList<MapData> getData() {
        try {
    
            String URL = "http://sml.com.pk/a/map.php";
            HttpParams httpparams = new BasicHttpParams();
    
            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("http", new PlainSocketFactory(), 80));
    
            DefaultHttpClient client = new DefaultHttpClient(
                    new ThreadSafeClientConnManager(httpparams, registry),
                    httpparams);
    
            HttpGet httpGet = new HttpGet(URL);
    
            HttpResponse response = client.execute(httpGet);
            String string_response = EntityUtils.toString(response.getEntity(),
                    "UTF-8");
            JSONArray JsonResponse;
            try {
                JsonResponse = new JSONArray(string_response);
    
                ArrayList<MapData> list = new ArrayList<MapData>();
                for (int i = 0; i < JsonResponse.length(); i++) {
                    String GPS = JsonResponse.getJSONObject(i).getString("GPS");
                    String temp[] = GPS.split(",");
                    MapData apoint = new MapData();
                    apoint.lat = temp[0];
                    apoint.lon = temp[1];
                    list.add(apoint);
    
                }
                return list;
            } catch (JSONException e) {
                e.printStackTrace();
                return null;
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
    
            e.printStackTrace();
            return null;
    
        }
    
    
    }
    
     public static class MapData {
            public String lat;
            public String lon;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Google V3 map which uses steetView and some map markers. The
I have an application based on google map, in which I need to use
I have a google map inside of a div which gets changed, its parent
i have a simple google map, showing the driving directions from NY to LA,
I have an App which launches the google Map App. The code is: UIApplication
I have a GWT web-app with a nearly full page Google map window. Inside
I have a present need to display a Google Map, inside a FancyBox. The
I have a google map inside a div that I need to be hidden
I have a page, and a Google Maps map is inside a hidden div
I have a google map that takes and put coordinates from input fields .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.