2017-02-11 60 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

你是在谈论深度链接 –

相关问题