繁体   English   中英

我怎样才能让它在谷歌地图上显示一个标记?

[英]how can I get this to display a marker on google maps?

我试图传递坐标和从 RSS 提要的点击收集的标题,我想将它从调试传递到谷歌地图,它确实通过而没有问题我的问题是在地图上显示它。 这是带有意图的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);
        }
    });

这是创建时的谷歌地图:

        @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        Intent intent = getIntent();
        intent.getStringExtra("title");
        intent.getStringExtra("location");

我只是不确定如何显示标记,所以当你点击它时你可以看到标题。

intent.getStringExtra("location");

location 参数是 LatLang,而不是 String,因此您无法从意图中获取位置。 所以最好分别发送 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");
...

通过这样做,您可以从意图中获取对象数据。 但是在这种情况下,您应该检查密钥,否则位置可能为空。 谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM