【问题标题】:Get the current location as google maps url when the button is pressed按下按钮时获取当前位置作为谷歌地图 url
【发布时间】:2017-06-29 14:48:17
【问题描述】:

这是我用来在按下按钮时将链接发送给同一聊天应用程序中的其他人的代码。

当按下按钮时,如何在同一个聊天应用程序中获取当前位置作为 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());

【问题讨论】:

标签: android google-maps android-gps


【解决方案1】:

试试这个

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"/>

【讨论】:

  • 嗨哈桑...我已经尝试过这段代码,但我的问题是当我按下我的应用程序中的按钮时,它应该将当前位置作为链接传递给同一个应用程序中的其他人(不共享链接或通过短信发送)。
  • 你说的是深度链接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-11
  • 1970-01-01
  • 2012-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-07
相关资源
最近更新 更多