Java 我怎样才能让它在谷歌地图上显示一个标记?
我正在尝试传递从RSS提要的点击中收集的坐标和标题,我想通过调试将其传递到google maps中,但没有问题我的问题是将其显示在地图上。这是一个带有意图的onclick:Java 我怎样才能让它在谷歌地图上显示一个标记?,java,android,google-maps,Java,Android,Google Maps,我正在尝试传递从RSS提要的点击中收集的坐标和标题,我想通过调试将其传递到google maps中,但没有问题我的问题是将其显示在地图上。这是一个带有意图的onclick: public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent in = new Intent(
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent in = new Intent(getApplicationContext(), MapsActivity.class);
String georss = ((TextView) view.findViewById(R.id.georss)).getText().toString();
String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
String[] latLng = georss.split(" ");
double lat = Double.parseDouble(latLng[0]);
double lng = Double.parseDouble(latLng[1]);;
LatLng location = new LatLng(lat, lng);
in.putExtra("location", location);
in.putExtra("title", title);
startActivity(in);
}
});
我只是不知道如何显示标记,所以当你点击它时,你可以看到标题
intent.getStringExtra("location");
位置参数是LatLang,而不是String,因此无法从intent获取位置。
因此,最好将lat和lng分开发送
...
in.putExtra("lat", lat);
in.putExtra("lng", lng);
startActivity(in);
...
Intent intent = getIntent();
double lat = intent.getDoubleExtra("lat", 0);
double lng = intent.getDoubleExtra("lng", 0);
...
[编辑]
或者您可以像这样解析LatLang数据
...
in.putExtra("location", location);
startActivity(in);
...
Intent intent = getIntent();
LatLng location = (LatLng) intent.getExtras().get("location");
...
通过这样做,您可以从intent获取对象数据。但是在这种情况下,您应该检查密钥,否则位置可以为null。
谢谢
...
in.putExtra("location", location);
startActivity(in);
...
Intent intent = getIntent();
LatLng location = (LatLng) intent.getExtras().get("location");
...