Pra*_*ane 1 android google-maps
我有一个应用程序,在点击按钮,或在更改地点,或在特定时间后,我能够获得经度和纬度值.我想使用此值在Google地图应用程序中显示它们.我打算使用意图显示位置,但不知何故它没有显示我得到的坐标.
这是我在我的一个应用程序中使用的一段代码.此代码还包括检查用户是否在其设备上安装了Google地图.如果检查将应用程序返回为已安装,则该函数会将数据传递给应用程序.如果检查失败,则会显示AlertDialog,通知用户未安装该应用程序.
protected void showMap() {
boolean installedMaps = false;
// CHECK IF GOOGLE MAPS IS INSTALLED
PackageManager pkManager = getPackageManager();
try {
@SuppressWarnings("unused")
PackageInfo pkInfo = pkManager.getPackageInfo("com.google.android.apps.maps", 0);
installedMaps = true;
} catch (Exception e) {
e.printStackTrace();
installedMaps = false;
}
// SHOW THE MAP USING CO-ORDINATES FROM THE CHECKIN
if (installedMaps == true) {
String geoCode = "geo:0,0?q=" + PLACE_LATITUDE + ","
+ PLACE_LONGITUDE + "(" + PLACE_NAME + ")";
Intent sendLocationToMap = new Intent(Intent.ACTION_VIEW,
Uri.parse(geoCode));
startActivity(sendLocationToMap);
} else if (installedMaps == false) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
CheckinsDetails.this);
// SET THE ICON
alertDialogBuilder.setIcon(R.drawable.ic_launcher);
// SET THE TITLE
alertDialogBuilder.setTitle("Google Maps Not Found");
// SET THE MESSAGE
alertDialogBuilder
.setMessage(R.string.noMapsInstalled)
.setCancelable(false)
.setNeutralButton("Got It",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.dismiss();
}
});
// CREATE THE ALERT DIALOG
AlertDialog alertDialog = alertDialogBuilder.create();
// SHOW THE ALERT DIALOG
alertDialog.show();
}
}
Run Code Online (Sandbox Code Playgroud)
下面提到的这行代码会将其发送到Google地图,而不是只显示Pin也会显示位置名称.
String geoCode = "geo:0,0?q=" + PLACE_LATITUDE + ","
+ PLACE_LONGITUDE + "(" + PLACE_NAME + ")";
Run Code Online (Sandbox Code Playgroud)
编辑:如果您不想显示PLACE_NAME,请geo:latitude,longitude
使用以下代码修改该特定行:而不是代码块中使用的行.
请查看此链接以获取更多可能的组合,例如缩放:http://developer.android.com/guide/appendix/g-app-intents.html