android :geo Location using intent
android :geo Location using intent
我有一个 ListView,当我单击单个项目时,它会转到单个项目视图。在每个单个项目视图页面中都有一个位置按钮。单击位置按钮
时我需要转到 google 地图
经度和纬度是这样保存在数据库中的。
我想动态地调用它
在 EACH CELL OF THE COLUMN 中,数据是这样存储的,
数据在解析数据库中存储为对象,而不是字符串
{"lat":25.1250241,"lng":55.3752069}
有人知道请告诉我如何从中获取数据?
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);
}
});
使用下面的方法从字符串中解析你的数据你需要在下面的方法中传递一个参数,当我传递字符串时。
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();
}
}
终于找到方法了..
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();
}
}
});
我有一个 ListView,当我单击单个项目时,它会转到单个项目视图。在每个单个项目视图页面中都有一个位置按钮。单击位置按钮
时我需要转到 google 地图经度和纬度是这样保存在数据库中的。 我想动态地调用它 在 EACH CELL OF THE COLUMN 中,数据是这样存储的,
数据在解析数据库中存储为对象,而不是字符串
{"lat":25.1250241,"lng":55.3752069}
有人知道请告诉我如何从中获取数据?
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);
}
});
使用下面的方法从字符串中解析你的数据你需要在下面的方法中传递一个参数,当我传递字符串时。
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();
}
}
终于找到方法了..
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();
}
}
});