[英]how can I get this to display a marker on google maps?
I am trying to pass coordinates and a title collected from an on click from an RSS feed and I want to pass it into google maps from the debug it does pass without issue my issue is displaying it on the map.我试图传递坐标和从 RSS 提要的点击收集的标题,我想将它从调试传递到谷歌地图,它确实通过而没有问题我的问题是在地图上显示它。 Here is the onclick with the intent:
这是带有意图的onclick:
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);
}
});
and here is the google maps on create:这是创建时的谷歌地图:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
Intent intent = getIntent();
intent.getStringExtra("title");
intent.getStringExtra("location");
I'm just not sure how to display the marker so when you click on it you can see the title.我只是不确定如何显示标记,所以当你点击它时你可以看到标题。
intent.getStringExtra("location");
The location parameter is LatLang, not String, so you can't get the location from intent. location 参数是 LatLang,而不是 String,因此您无法从意图中获取位置。 So it's better to send lat and lng separately.
所以最好分别发送 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);
...
[Edit] [编辑]
Or you can parse LatLang data like this.或者您可以像这样解析 LatLang 数据。
...
in.putExtra("location", location);
startActivity(in);
...
Intent intent = getIntent();
LatLng location = (LatLng) intent.getExtras().get("location");
...
By doing like that, you can get Object data from intent.通过这样做,您可以从意图中获取对象数据。 But in this case, you should check the key, otherwise the location can be null.
但是在这种情况下,您应该检查密钥,否则位置可能为空。 Thanks.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.