这是我按下按钮时用于将链接发送给同一聊天应用程序中其他人的代码。
当按下按钮时,如何将当前位置作为google maps 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 :(得分: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"/>