【问题标题】:Opening Maps via intent the first time centers on user location, ignores geo:第一次通过意图打开地图以用户位置为中心,忽略地理:
【发布时间】:2013-08-20 15:49:54
【问题描述】:

我已经看到到处张贴这个例子,以打开以特定点为中心的谷歌地图:

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

但是在我看来,至少在最新的地图版本中,第一次调用它时会忽略这一点,而是缩放到用户位置。这是一个错误吗?

【问题讨论】:

  • 这也发生在我身上...使用 Android 4.2.2

标签: android google-maps android-intent


【解决方案1】:

我能够通过 AsyncTask 两次调用意图来解决这个问题。我不知道这是否是正确的方法,但它对我有用!

这是我的代码:

@Override
public void onClick(View v) {
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%f,%f(%s)&z=40", lat, lon, square);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            mContext.startActivity(intent);
            return null;
        }
        @Override
        protected void onPostExecute(Void result) {
            String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%f,%f(%s)&z=40", lat, lon, square);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            mContext.startActivity(intent);
        }
    }.execute();
}

【讨论】:

    【解决方案2】:

    我意识到我从未回答过这个问题。这最终是我使用的,它似乎工作正常。上面的答案也可以!

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                    Uri.parse("http://maps.google.com/maps?q="+lat+","+lon);
    startActivity(intent);
    

    除了在驾驶模式下启动地图之外,要执行相同的操作,请执行以下操作:

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                    Uri.parse("http://maps.google.com/maps?daddr="+lat+","+lon);
    startActivity(intent);
    

    【讨论】:

      猜你喜欢
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多