Question

My question is this:

How can I share the location of a marker I place on the map via touch position(Google Maps V2) I have an info window and can see the lat long. I tried and tried to set a button on the map to send the location of the placed marker, and I just can't get it to work.

Please help me to solve this issue.

Here is the code logic I have used:

public void setSendButton(Button sendButton) {
    sendButton = (Button) findViewById(R.layout.mymap);}


        public void onClick(View v, String Location) {

            Context context = getApplicationContext();

            SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

            if (googleMap.getMyLocation() != null) {
                 googleMap.getMyLocation();
            }

            Intent i = new Intent(android.content.Intent.ACTION_SEND);
            Location = location.getLatitude() / 1E6 + "," + location.getLongitude() / 1E6;
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_SUBJECT, settings.getString("message_subject", getString(R.string.share_location_subject)));
            i.putExtra(Intent.EXTRA_TEXT, settings.getString("message_body", getString(R.string.share_location_body))
                    + " http://maps.google.com/maps?q=loc:"
                    + location);

            try {
                startActivity(Intent.createChooser(i, getString(R.string.share_title)));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(context, getString(R.string.no_way_to_share), Toast.LENGTH_LONG).show();
            }    
Was it helpful?

Solution

Observation and Answer was correct code was just static via misplaced logic. Turns out I did not need a button.

Lesson is just use the objects methods.

Thanks to all.

Mike

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top