简体   繁体   English

如何在Android中使用Google API打开特定城市的地图

[英]how to open up a map of a particular city using google APIs in android

I have been able to open up a map of the world through code and mark a few places. 我已经能够通过代码打开世界地图并标记一些地方。 However, I always have to zoom down to the city, which takes a little while. 但是,我总是必须缩小到城市,这需要一些时间。 Is there any way to directly open up a map of a particular city? 有什么方法可以直接打开特定城市的地图吗?

You can use moveCamera with your last stored location (lat, lng and maybe zoomLevel too) for example. 例如,您可以将moveCamera与最后存储的位置(lat,lng或zoomLevel)一起使用。

final LatLng location = new LatLng(..., ...);// Loaded from SharedPreferences maybe.

// Move the camera to location with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 15));

You can use this sample code to animate the map directly to your city coordinate (lat, lng) and automatically zooming out to specified level : 您可以使用以下示例代码将地图直接设置为城市坐标(纬度,经度)的动画,并自动缩小到指定级别:

// Set desired lat lng location, and zoom level (for example 10)
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(locationCity.getLatitude(), locationCity.getLongitude()), 10);
// Move the camera to location
gMap.animateCamera(cameraUpdate);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM