有些應用需要打開谷歌地圖應用,通過傳遞的經緯度,在地圖中顯示出對應的位置,標記marker圖標等功能,代碼如下:
// 指定地圖顯示的等級
int zoomLevel=16;
// 根據經緯度搜索
String location=String.format("geo:%s,%s", latitude, longitude);
//搜索條件,條件後面可以添加一個標題,格式如“(xxxx)” 這個標題將在地圖的marker上顯示出來
String query = Uri.encode(String.format("%s,%s", latitude,longitude));
String path = String.format("%s?q=%s&z=%d", location,query,zoomLevel);
//根據地址進行搜索
String location=String.format("geo:%s,%s", latitude, longitude);
String path = String.format("%s?q=%s&z=%d", location,address,zoomLevel);
Uri uri = Uri.parse(path);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);