Question

I am developing an emergency application for my school, and I had a question. I have code that gets your coordinates, and smsmanager sends them to a designated phone number. I tried to put the coordinates in a Google Maps link so the recipient can just click a link instead of inputting the coordinates into Google Maps, but when I do, the link is broken by the "=", "<" and ">" signs. I was wondering what I could do in my code to make the link work. When the recipient receives the message, it looks like this..

"http://maps.google.com/?q"=<"######">,<"######">

Everything in quotations is a link, the rest is not.

public void onClick(View v) {

try {

                    txtLat = (TextView) findViewById(R.id.textview1);
                    String messageToSend = txtLat.getText().toString();
                    String number = "8143664050";
                    SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);

                    Toast.makeText(getApplicationContext(), "Help SMS Sent",
                            Toast.LENGTH_LONG).show();


                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(), "SMS failed!",
                            Toast.LENGTH_LONG).show();
                    e.printStackTrace();
                }
            }
        });
    }

}

@Override
public void onLocationChanged(Location location) {
    txtLat = (TextView) findViewById(R.id.textview1);
    txtLat.setText("http://maps.google.com/?q=<" + location.getLatitude() + ">,<" + location.getLongitude() + ">");

}
Was it helpful?

Solution

try:

int zoom = 12;
txtLat.setText(
        "https://www.google.com/maps/@" + location.getLatitude() + "," + 
        location.getLongitude() + "," + zoom + "z");

for 3d/satellite map:

txtLat.setText(
        "https://www.google.com/maps/@" + location.getLatitude() + "," + 
        location.getLongitude() + ",15000m/data=!3m1!1e3");

The address should be automatically updated when you are using Google Maps, try around and see how it changes.

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