在android中打开谷歌地图

时间:2015-02-15 13:41:11

标签: android google-maps

我在这里打开带有GPS点的地图,所以:

 String geoUri = String.format("geo:%s,%s?z=15", Double.toString(lat), Double.toString(lng)); 
 Uri geo = Uri.parse(geoURI); 
 Intent geoMap = new Intent(Intent.ACTION_VIEW, geo); 
 startActivity(geoMap); 
谷歌专注于地图的正确位置,但没有设定点。谷歌地图缺少什么?

1 个答案:

答案 0 :(得分:1)

尝试使用geo:0,0?q=lat,lng(label)given longitude and latitude with a string label显示地图。 示例:"geo:0,0?q=34.99,-106.61"

示例代码:

Uri geoLocation = Uri.parse("geo:0,0?").buildUpon()
                .appendQueryParameter("q", Double.toString(lat), Double.toString(lng))
                .build();

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(geoLocation);

        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            // Error            
        }

有关详细信息,请参阅here

相关问题