【问题标题】:Launch Google Maps app启动谷歌地图应用
【发布时间】:2010-03-31 13:25:24
【问题描述】:

我正在尝试从我的应用程序中启动 Google 地图。我正在使用:

GeoPoint center = _mapView.getMapCenter(); 

Uri uri = Uri.parse("geo:"+center.getLatitudeE6()+","+center.getLongitudeE6()); 

Log.d(LOG_TAG, "Launching Google Maps with Uri: ("+uri+")"); 
Intent intent = new Intent(Intent.ACTION_VIEW, uri);

startActivity(intent); 

我使用以纽约市某处为中心的地图对其进行了测试,但谷歌地图打开时并没有以那里为中心。 我按照 Android Developer 的网站参考使用:“geo:latitude,longitude”模式。

您看到的打印日志:

Launching Google Maps with Uri: (geo:40763500,-73979305) 

谁知道问题出在哪里?

【问题讨论】:

    标签: android google-maps android-intent


    【解决方案1】:

    尝试使用:

    Uri uri = Uri.parse("geo:"+(center.getLatitudeE6()/1E6)+","+(center.getLongitudeE6()/1E6)); 
    

    geo: Uri 格式采用十进制纬度/经度,而不是 E6 格式(度 * 1E6)。

    【讨论】:

      【解决方案2】:

      您需要除以 1E6,因为 GeoPoint 不返回双精度值。

      Uri uri = Uri.parse("geo:"+(center.getLatitudeE6()/1E6)+","+(center.getLongitudeE6()/1E6));
      

      我个人喜欢这种方式,daddr 是(center.getLatitudeE6()/1E6)+","+(center.getLongitudeE6()/1E6)

      startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?f=d&saddr="+saddr+"&daddr="+daddr+"&hl=en")));
      

      【讨论】:

        猜你喜欢
        • 2011-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多