简体   繁体   English

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

[英]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.

相关问题 如何从 Google 地图中的可拖动标记中获取 position? - How can I get position from a draggable marker in Google Maps? 如何获得正常的谷歌地图蓝色当前位置标记? - How can I get the normal Google Maps blue current location marker? 如何通过使用Google Maps获取用户当前位置并在android中放置标记 - How can i get the user current location and put marker on it in android by using google maps 如何获得谷歌地图标记的图标? - How to get Icon of Google Maps marker? 如何从另一个Google地图的标记获取以分钟为单位的持续时间 - How get duration in mins from a marker another google maps 如何使用MSExcel中的纬度和经度对在Google地图上移动标记并每10秒刷新一次 - How can I move a marker on Google Maps using latitude & longitude pair from MSExcel and refresh every 10 seconds 如何在Google地图中输入的地址上放置标记? - How to place marker on entered address in Google Maps? 如何在不使用谷歌地图和其他地图的情况下获取用户当前位置? - How can I get user current location without using google maps and other maps? 如何在Google Map API V3中获取位置标记? - how can i get place marker in google map api v3? Android:Google Maps Fragment。 在新活动中显示标记信息 - Android: Google Maps Fragment. Display marker information in a new activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM