android :geo Location using intent

一世执手 提交于 2019-12-08 02:07:44

问题


I have a ListView and when i click a single item it goes to single item view . in each single item view page there is a location button .I need to go to google map when click the location button

longtitute and latitudes are saved in database like this . I want to call this dynamically in EACH CELL OF THE COLUMN , data is stored like this,


the data is stored as object inside parse database, not as strings

{"lat":25.1250241,"lng":55.3752069}

anyone knows please tell how can i get data from this?

           btn = (Button) findViewById(R.id.button5) ;
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {


                    btn = (Button) findViewById(R.id.button56) ;
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    String data = String.format("geo:%s,%s", latitude, longitude);

                    intent.setData(Uri.parse(data));
                    startActivity(intent);
                }
            });

回答1:


Use Below method to parse your data from String you need pass one paramaeter in below method when I passes string.

private void parseJsonData(){
        try {
            String jsonString = "{\"lat\":25.1250241,\"lng\":55.3752069}";
            Object object = new JSONTokener(jsonString).nextValue();
            if (object instanceof JSONObject) {
                JSONObject jsonObject = (JSONObject) object;
                double lat = Double.parseDouble(jsonObject.optString("lat"));
                double lng = Double.parseDouble(jsonObject.optString("lat"));

                Log.i(getClass().getSimpleName(),"lat="+lat);
                Log.i(getClass().getSimpleName(),"lng="+lng);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }



回答2:


finally found way ..

this is the code i use to get only the coordinates

   showCorporate = (Button) findViewById(R.id.individualEmail);
        showCorporate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String[] location = corporateLocation.split(",");
                double lat, lng;
                try{
                    lat = fetchDouble(location[0], true);
                    lng = fetchDouble(location[1], false);
                    Log.d("Co-Ordinates",""+lat+", "+lng);
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    String data = String.format("geo:%s,%s", lat, lng);
                    intent.setData(Uri.parse(data));
                    startActivity(intent);
                }catch (NullPointerException npe){
                    Toast.makeText(SingleCorporate.this, "Sorry No Location Available!", Toast.LENGTH_SHORT).show();
                }
            }
        });


来源:https://stackoverflow.com/questions/42468580/android-geo-location-using-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!