Android的谷歌地图没有加载在活动小版面 [英] Android Google Map not loading in activity small layout
问题描述
在我的应用程序正在使用中的活动地图视图底部side.but地图不加载properly.after点击地图上2-3倍的显示效果清晰地图和放大器。在同一张地图,如果负载在众目睽睽它加载清楚。 如何解决这个?
截屏是 -
< com.google.android.gms.maps.MapView
机器人:ID =@ + ID /图
机器人:layout_width =FILL_PARENT
机器人:layout_height =200dp
机器人:layout_margin =10dp/>
Java的code -
尝试{
MapsInitializer.initialize(getApplicationContext());
}赶上(GooglePlayServicesNotAvailableException E){
// TODO自动生成的catch块
e.printStackTrace();
}
开关(GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()))
{
案例ConnectionResult.SUCCESS:
图形页面=(图形页面)findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
//获取从图形页面来使用GoogleMap并执行初始化的东西
如果(图形页面!= NULL)
{
地图= mapView.getMap();
map.getUiSettings()setMyLocationButtonEnabled(假)。
map.setMyLocationEnabled(真正的);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(locationPosition,10);
map.animateCamera(cameraUpdate);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
打破;
案例ConnectionResult.SERVICE_MISSING:
打破;
案例ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
打破;
默认:Toast.makeText(getApplicationContext(),GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()),Toast.LENGTH_SHORT).show();
}
CameraPosition cameraPosition =新CameraPosition.Builder()
.TARGET(locationPosition).zoom(10).bearing(0)//设置摄像头向东的方向
.tilt(70)//摄像机的倾斜设置为30度
。建立(); //创建从制造商一个CameraPosition
map.setBuildingsEnabled(真正的);
map.setMyLocationEnabled(真正的);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
map.addMarker(新MarkerOptions().position(locationPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marker)));
我(我坚持用工作,即使它是pcated在这一点上德$ P $的MapView)一个非常类似的问题。 这是我的问题,也是我的回答:<一href="http://stackoverflow.com/questions/32908988/android-map-loading-very-slow-not-loading-at-all-in-started-activity-until-click">Android地图加载速度很慢/没有加载在所有在活动开始之前,点击它
您需要实现以下方法: OnResume();将OnPause();的onDestroy(); onLowMemory();
希望它帮助。
In my application i'm using map view in activity at bottom side.but map doesn't load properly.after clicking on map 2-3 time its shows clear map.& when same map if load in full view it's loading clearly. What is the solution for this?
screen shot is-
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="10dp" />
java code-
try {
MapsInitializer.initialize(getApplicationContext());
} catch (GooglePlayServicesNotAvailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()) )
{
case ConnectionResult.SUCCESS:
mapView = (MapView)findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
if(mapView!=null)
{
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(locationPosition, 10);
map.animateCamera(cameraUpdate);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
break;
case ConnectionResult.SERVICE_MISSING:
break;
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
break;
default: Toast.makeText(getApplicationContext(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()), Toast.LENGTH_SHORT).show();
}
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(locationPosition).zoom(10).bearing(0) // Sets the orientation of the camera to east
.tilt(70) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
map.setBuildingsEnabled(true);
map.setMyLocationEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
map.addMarker(new MarkerOptions() .position(locationPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marker)));
I had a very similar problem(I insisted working with the MapView even though it is deprecated at this point). Here it is my issue and also my answer: Android Map loading very slow/not loading at all in started activity until clicking on it
You need to implement the following methods: OnResume(); OnPause(); onDestroy(); onLowMemory();
Hope it helps.
这篇关于Android的谷歌地图没有加载在活动小版面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!