2017-02-11 59 views
-1

這是我用來在按下按鈕時將鏈接發送給其他人的代碼。當按鈕被按下時,獲取當前位置作爲谷歌地圖URL

當按下按鈕時,如何才能將當前位置作爲谷歌地圖url在同一個聊天應用中?

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()); 
+0

我們不知道是什麼'mChatApplication'是......請顯示[MCVE]你的問題在[編輯] –

+0

你可以嘗試這個https://github.com/akhgupta/Android-EasyLocation – Akhil

回答

0

試試這個

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. 


     } 
    }); 

中添加這些權限您的清單

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
+0

嗨哈桑...我已經試過這段代碼,但我的問題是當我按下按鈕在我的應用程序它應該通過當前位置作爲同一應用中其他人的鏈接(不共享鏈接或通過短信發送)。 –

+0

你是在談論深度鏈接 –

相關問題