本文介绍了如何获取存储在MySQL的经纬度位置,并使用它的Andr​​oid地图应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让被存储在MySQL中的纬度和经度位置。我想使用的值来我的Andr​​oid地图应用程序。

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.

下面是我的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);
}
});

这里是 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();
    }
}

}

其结果是在地图应用目的的EditText Android版

The result is in destination EditText in maps application for Android

"null,null"

如何使destination_latitude,destination_longitude?

How to make it "destination_latitude, destination_longitude"?

请帮助我。

推荐答案

字符串des_lat = z.getExtras()的getString(键);

String des_lat = z.getExtras().getString(key);

试试这个其对您有所帮助。

try this its helpful to you

这篇关于如何获取存储在MySQL的经纬度位置,并使用它的Andr​​oid地图应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 19:17