-1

This the code I used to send the link to others in same chat application when the button is pressed.

How can I get the current location as google maps url in same chat app when the button is pressed?

TextView link = (TextView) findViewById(R.id.TextView1);
String linkText = "https://www.google.co.in/maps?geo:0,0?q=my+street+address?geo:latitude,longitude";
mChatApplication.newLocalUserMessage(linkText);
link.setText(linkText);
link.setMovementMethod(LinkMovementMethod.getInstance());
Asif Patel
  • 1,744
  • 1
  • 20
  • 27

1 Answers1

0

try this

currentLocation = (Button) findViewById(R.id.currentLocation);
    currentLocation.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // instantiate the location manager, note you will need to request permissions in your manifest
            LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            // get the last know location from your location manager.
            if (ActivityCompat.checkSelfPermission(MapsActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                    ActivityCompat.checkSelfPermission(MapsActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

            // now get the lat/lon from the location and do something with it.


        }
    });

add these permissions in your manifest

 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Hasan shaikh
  • 738
  • 1
  • 6
  • 16
  • Hi Hasan...I already tried this code but my problem is when I pressed the button in my app it should pass the current location as link to others in the same app(not to share the link or sending via sms). – Pavithra M Feb 11 '17 at 13:12
  • Are you talking about deep linking – Hasan shaikh Feb 13 '17 at 03:45