Emv*_*ver 6 camera android move google-maps-android-api-2
我是一个真正的谷歌地图API菜鸟,所以任何帮助表示赞赏.我想在这里看到的是,当我打开我的应用程序时,相机需要直接移动到我当前的位置并放置蓝点.我该如何设法做到这一点?
我已经制作了一个示例代码,以便每个人都能理解它并在需要时实现它们的代码:
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.general_map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
if( helper.isGPSEnabled() ){
map.move... // move directly to my current position
}
Run Code Online (Sandbox Code Playgroud)
请帮忙...
小智 28
这就是我能够工作的原因.它显示您当前的位置并在那里放置一个标记.这适用于Google Maps API v2
private void setUpMap() {
// Enable MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
// Get LocationManager object from System Service LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Create a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Get the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);
// Get Current Location
Location myLocation = locationManager.getLastKnownLocation(provider);
//set map type
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// Get latitude of the current location
double latitude = myLocation.getLatitude();
// Get longitude of the current location
double longitude = myLocation.getLongitude();
// Create a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
// Show the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("You are here!"));
}
Run Code Online (Sandbox Code Playgroud)
您需要首先确定用户的位置。之后,您在地图上设置纬度和经度。另外,不要忘记设置缩放级别以放大地图。
确定 GPS 是否启用:
有关位置策略的更多信息:
http://developer.android.com/guide/topics/location/strategies.html
| 归档时间: |
|
| 查看次数: |
17494 次 |
| 最近记录: |