[英]Override default log location for JMeter when launching with Java (not command line)
[英]Override Default Location on Android Phone using Java
我遵循了24小时的教科书,并创建了一个Android应用程序,该应用程序应启动Google地图并根据硬编码到应用程序中的经纬度坐标导航到特定位置。 但是,当我启动该应用并运行代码时,它会打开Google地图或Google Earth,并且始终默认为我当前的位置。 如何防止它这样做?
我正在尝试让我的应用转到特定的经度和纬度,但是当它启动Google地图或Google地球时,它始终默认为我当前的位置。 Java代码如下:
Button mapButton = (Button) findViewById(R.id.button2);
mapButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view) {
String geoURI = "geo:37.422,-122.0847z=23";
Uri geo = Uri.parse(geoURI);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, geo);
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
如何获取它来覆盖默认位置并转到我上面已硬编码的坐标?
查看文档 ,该行:
String geoURI = "geo:37.422,-122.0847z=23";
似乎是无效的语法,但可能要缩放。 尝试:
String geoURI = "geo:37.422,-122.0847?z=23";
缩放级别最多只能达到21,但是,请尝试:
String geoURI = "geo:37.422,-122.0847?z=21";
如果都不起作用,请使用没有任何缩放的基本字符串:
String geoURI = "geo:37.422,-122.0847";
尝试这个:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);
如果您不想要标签,则可以省略(标签+名称),标签会根据最近的街道或它认为相关的其他内容随机选择一个。
您可以创建LatLng对象,并告诉Google地图加载位置。 这样做的代码将是这样的:
double lat=26.52719;
double lng=88.72448;
LatLng myLocation = new LatLng(lat,lng);
if(this.googleMap !=null){
this.googleMap.addMarker(new MarkerOptions().position(myLocation).title("Your current Location").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
this.googleMap.moveCamera(CameraUpdateFactory.newLatLng(myLocation));
}
请记住,您应该在onMapReady回调中应用此功能,并关闭当前在Google地图中的位置,您可以
this.googleMap.setMyLocationEnabled(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.