Marc Leese
Marc Leese

Reputation: 31

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. Here is the onclick with the 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);
        }
    });

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.

Upvotes: 0

Views: 46

Answers (1)

Green Y.
Green Y.

Reputation: 506

intent.getStringExtra("location");

The location parameter is LatLang, not String, so you can't get the location from intent. So it's better to send lat and lng separately.

...
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.

...
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.

Upvotes: 1

Related Questions