Search code examples
javaandroidstring-concatenation

Android how can I get coordinates and add it to link automatically


I'm developing an application that organized my addresses, and I would like to achieve the following:

When I click on the add address button there will be two text boxes, Name and Link. I want the Link text box to get the current location automatically and add the coordinates to this URL:

http://maps.google.com/maps?q=

For example this is the coordinates 27.123456,49.123456 so the final result will be like this:

http://maps.google.com/maps?q=27.123456,49.123456

I searched for hours but all I manged to do is to get the current location coordinates. So please guys if any one can help me with it I'll be extremely thankful.

*** Update this is the problem now :

public void buildLink(float textLatt, float textLot) {
return String.format("http://maps.google.com/maps?q=%f,%f", textLatt, textLot);
}

Solution

  • txtmylink.setText(
        String.valueOf("http://maps.google.com/maps?q=") + 
        String.valueOf(mLastLocation.getLatitude()) +
        String.valueOf(",") + 
        String.valueOf(mLastLocation.getLongitude()));