How to get latitude and longitude position that stored in MySQL and use it in Android map application
Posted
by
gunawan haruna
on Stack Overflow
See other posts from Stack Overflow
or by gunawan haruna
Published on 2012-11-09T06:14:28Z
Indexed on
2012/11/24
5:05 UTC
Read the original article
Hit count: 211
I have tried to get the latitude and longitude position that was stored in MySQL. I want use the values to my Android map application.
Here is my code:
deskripsi.Java
Button direction = (Button) findViewById (R.id.btnDir);
direction.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
Intent z = getIntent();
des_lat = z.getExtras().getString("des_lat");
des_long = z.getExtras().getString("des_long");
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?&daddr="+des_lat+","+des_long));
//("geo:37.827500,-122.481670"));
startActivity(i);
}
});
And here is the content.Java
private ListView list;
int x;
private String panjang[];
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.kontent);
super.initButtonSearch();
list = (ListView) findViewById(R.id.list);
JSONObject jo;
try {
jo = new JSONObject(JsonKontent);
JSONArray ja = jo.getJSONArray("result");
System.out.println("Panjang : " + ja.length());
if (ja.length() == 0) {
Toast.makeText(Content.this, "Data tidak ada!",
Toast.LENGTH_LONG).show();
finish();
}
content_id = new String[ja.length()];
c_title = new String[ja.length()];
c_telephone = new String[ja.length()];
c_short_description = new String[ja.length()];
c_long_description = new String[ja.length()];
c_image1 = new String[ja.length()];
c_image2 = new String[ja.length()];
l_address = new String[ja.length()];
catagory_id = new String[ja.length()];
Location myLoc = new Location("sharedPreferences");
Location restLoc = new Location("restaurantTable");
l_latitude = new String[ja.length()];
l_longitude = new String[ja.length()];
c_name = new String[ja.length()];
panjang = new String[ja.length()];
for (x = 0; x < ja.length(); x++) {
JSONObject joj = ja.getJSONObject(x);
content_id[x] = joj.getString("content_id");
catagory_id[x] = joj.getString("catagory_id");
c_title[x] = joj.getString("c_title");
c_telephone[x] = joj.getString("c_telephone");
c_short_description[x] = joj.getString("c_short_description");
c_long_description[x] = joj.getString("c_long_description");
c_image1[x] = HTTPConnection.urlPicture
+ joj.getString("c_image1");
c_image2[x] = HTTPConnection.urlPicture
+ joj.getString("c_image2");
l_address[x] = joj.getString("l_address");
l_latitude[x] = joj.getString("l_latitude");
l_longitude[x] = joj.getString("l_longitude");
c_name[x] = joj.getString("c_name");
myLoc.setLatitude(myLatitude);
myLoc.setLongitude(myLongitude);
restLoc.setLatitude(Double.parseDouble(l_latitude[x]));
restLoc.setLongitude(Double.parseDouble(l_longitude[x]));
float f = myLoc.distanceTo(restLoc);
int f_int = Math.round(f / 100);
f = Float.valueOf(f_int) / 10;
String dist = new DecimalFormat("#,##0.0").format(f);
System.out.println("Panjang " + dist + " km");
panjang[x] = dist + " km";
}
} catch (JSONException e) {
Toast.makeText(Content.this, "Data yang dicari tidak ada!",
Toast.LENGTH_LONG).show();
finish();
}
PFCAdapter adapter = new PFCAdapter(this, c_image1, c_title, l_address,
panjang);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
System.out.println("Content ID: "
+ Content.content_id[Deskripsi.id]);
Deskripsi.id = arg2;
waitDialog = ProgressDialog.show(Content.this, "Memuat",
"Harap tunggu, sedang terhubung dengan server");
waitDialog.setIcon(R.drawable.iconnya);
waitDialog.show();
new LihatRatingTask().execute();
}
});
}
class LihatRatingTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... Arg0) {
Deskripsi.jsonRating = HTTPConnection.openUrl(HTTPConnection.host
+ "lihat_rating.php?content_id="
+ Content.content_id[Deskripsi.id]);
Deskripsi.jsonSubCategory = HTTPConnection
.openUrl(HTTPConnection.host
+ "sub_catagory_parameter.php?content_id="
+ Content.content_id[Deskripsi.id]);
RoutePath.place = HTTPConnection
.LoadImageFromWeb(HTTPConnection.host
+ "Logo/"
+ image[Integer.valueOf(catagory_id[Deskripsi.id]) - 1]);
Intent i = new Intent(Content.this, Deskripsi.class);
i.putExtra("des_lat", l_latitude);
i.putExtra("des_long", l_longitude);
startActivity(i);
waitDialog.dismiss();
return null;
}
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
waitDialog.dismiss();
}
}
}
The result is in destination EditText
in maps application for Android
"null,null"
How to make it "destination_latitude, destination_longitude"?
Help me please.
© Stack Overflow or respective owner