我想展示特定城市的地图,当用户选择任何城市时,只显示该城市的区域,而不是整个地图。我需要一些关于如何实现这种功能的建议。
谢谢提前。
我想展示特定城市的地图,当用户选择任何城市时,只显示该城市的区域,而不是整个地图。我需要一些关于如何实现这种功能的建议。
谢谢提前。
String uri = "geo:"+ latitude + "," + longitude;
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
// You can also choose to place a point like so:
String uri = "geo:"+ latitude + "," + longitude + "?q=my+street+address";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
/*
* The Possible Query params options are the following:
*
* Show map at location: geo:latitude,longitude
* Show zoomed map at location: geo:latitude,longitude?z=zoom
* Show map at locaiton with point: geo:0,0?q=my+street+address
* Show map of businesses in area: geo:0,0?q=business+near+city
*/
在这里,我们需要为每个城市进行RND,找出每个城市的纬度和经度。因此,为了找到每个城市的纬度和经度,不需要去那里检查纬度和经度。简单的方法是通过移动地图查找坐标。 因此,在获取每个城市的所有纬度和经度之后,使用这些纬度和经度根据用户选择的城市显示地图。这样它将显示特定区域。 因此,请检查以下代码如何使用纬度和经度来显示地图。
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:0,0?q=" + ("40.7890011, -124.1719112")));
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
首先您需要要求用户选择一个城市,然后使用 Geocoder 类来查找该城市的纬度和经度,请使用以下代码:
MapController mControl;
MapView mapView;
mapView= (MapView) findViewById(R.id.navView)
mControl = mapView.getController();
mControl.animateTo(GeoP); //GeoP is the geopoint of your city
有一个很好的用于此目的的类叫做Geocoder
这里是参考资料
你可以直接使用方法
getFromLocationName("My Particular city", ...)
获取与之匹配的位置列表。通常第一个是您需要的。
我猜这是唯一的方法。虽然非常有用。 :)
希望有所帮助!)