【问题标题】:sending location to google map with latitude and longitude将位置发送到带有纬度和经度的谷歌地图
【发布时间】:2015-04-14 16:55:41
【问题描述】:

这就是我获取当前位置的方式。现在我的问题是,有没有办法让这个纬度和经度成为用户可以点击的链接,并且当前位置将显示在 GoogleMap 上。因为我将通过短信将此链接发送到另一个 android,当他单击该链接时,他的手机中的 Google 地图安装将打开,或者 Googlemap 网站将打开,并且通过 lang 和 lat 获取的位置将显示在地图上。不知道如何实现它有什么帮助吗?

   public void onLocationChanged(Location location) {

            mLocationView.setText("Location received: "+ location.getLatitude() + location.getLongitude());

【问题讨论】:

  • 你是在使用 Phonegap/Cordova 还是原生 android

标签: android google-maps geolocation


【解决方案1】:

要构建一个可以添加到 SMS 消息中的简单 URL,您可以执行以下操作:

String link = "http://maps.google.com/maps?q=loc:" + String.format("%f,%f", location.getLatitude() , location.getLongitude() );

例如这段代码:

double lat = 37.77657;
double lon = -122.417506;
String link = "http://maps.google.com/maps?q=loc:" + String.format("%f,%f", lat, lon);

像这样构造一个链接:

http://maps.google.com/maps?q=loc:37.776570,-122.417506

有关详细信息,请参阅this question

【讨论】:

    【解决方案2】:

    使用下面的代码

    String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    context.startActivity(intent);
    

    【讨论】:

    • 这并不能完全回答问题。他在问如何构建将在 SMS 消息中发送的链接。
    • 是的 @DanielNugent 这就是我要问的用我的纬度和经度构建链接,这将打开 googlemap 并向我显示位置
    • @Brendom 您将从哪里发送短信,您是否短信网关始终相同。我的意思是短信发件人总是一样的??
    猜你喜欢
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多