我需要我的Android应用程序的地图引脚下拉动画.做了很多研究,我没有发现任何有用的东西.所以我创造了一个小黑客.只需发布代码,以便其他人可以使用它并相应地修改它.
由于Android中的翻译动画仅适用于视图而叠加不是视图,我创建了一个小的黑客,它通过翻译动画将视图放在同一个地理位置,然后删除视图以显示叠加.这样,用户认为地图叠加层从顶部开始掉落,即使它们不是.
这是代码:
private void translateAnimation(MapView mapView,ArrayList<GeoPoint> geoPointsList,Context context) {
Point dropPoint = new Point();
Projection projection = mapView.getProjection(); /*
* Getting the map projections to calculate
* screen points and geopoints
*/
GeoPoint mGeoPoint = projection.fromPixels(0, 0);
/* Map View screen parameters */
MapView.LayoutParams screenParameters = new MapView.LayoutParams(
MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT, mGeoPoint, 0,
0, MapView.LayoutParams.LEFT | MapView.LayoutParams.BOTTOM);
for (GeoPoint geoPoint : geoPointsList) {
projection.toPixels(geoPoint, dropPoint); /*
* As Overlays are not a subclass of views so
* view animation cannot …Run Code Online (Sandbox Code Playgroud) 我想在我的MapView上使用onZoomListener.下面的代码就是我所做的.它会记录是否点按了缩放按钮.由于所有新手机现在都支持缩放,这是没用的.有没有人知道如何真正做onZoomListener?谢谢.
OnZoomListener listener = new OnZoomListener() {
@Override
public void onVisibilityChanged(boolean arg0) {
// TODO Auto-generated method stub
}
@Override
public void onZoom(boolean arg0) {
Log.d(TAG, "ZOOM CHANGED");
// TODO Auto-generated method stub
}
};
ZoomButtonsController zoomButton = mapView.getZoomButtonsController();
zoomButton.setOnZoomListener(listener);
Run Code Online (Sandbox Code Playgroud) 我想在一点上删除我的地图的所有叠加,我尝试了不同的方式,但它永远不会工作.
最后一次尝试我做了[self.mapView removeOverlays:self.mapView.overlays];它仍然无法正常工作.知道如何删除那些叠加层吗?
谢谢.
更新1
我有错误: malloc: *** error for object 0x5adc0c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
我想我知道为什么,但是真的不知道如何解决它...当我需要在mapView上绘制另一行时,这是代码:
// Create a c array of points.
MKMapPoint *pointsArray = malloc(sizeof(CLLocationCoordinate2D) * 2);
// Create 2 points.
MKMapPoint startPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(oldLatitude, oldLongitude));
MKMapPoint endPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(newLatitude, newLongitude));
// Fill the array.
pointsArray[0] = startPoint;
pointsArray[1] = endPoint;
// Erase polyline and polyline view if not nil.
if (self.routeLine != nil) { …Run Code Online (Sandbox Code Playgroud) 我们在应用程序中使用Google MapView,但在不同的计算机上,我们必须使用不同的API密钥,否则MapView不会显示任何内容.
有没有办法为所有开发人员设置一个密钥?
我正在尝试在片段中显示MapView(使用被黑客入侵的兼容性库).以下在过去工作得很好:
onCreateView()只是返回一个新的FrameLayoutonActivityCreated()从Acitivity获取MapView并将其添加到其视图层次结构中onDestroyView() 从视图层次结构中删除MapView现在我希望片段使用xml中定义的布局,这样我就可以拥有其他一些UI内容.将MapView元素放在布局文件中总是崩溃,所以我这样做:
map_screen_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/map_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我MapScreenActivity保持实际MapView和片段调用getMapView(),所以我不会遇到"不能有多个MapView"的问题:
MapScreenActivity.java
public class MapScreenActivity extends FragmentActivity {
protected Fragment fragment;
protected MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_pane_empty);
if (savedInstanceState == null) {
fragment = new MapScreenFragment();
getSupportFragmentManager().beginTransaction().add(R.id.root_container, fragment)
.commit();
}
}
public MapView getMapView() {
if (mapView == null) …Run Code Online (Sandbox Code Playgroud) 我已将google-play-services_lib导入我的工作区并将google项目添加到MYProject中它会给出错误:
描述资源路径位置类型的容器 'Android的依赖' 引用不存在的库 'd:\ Android的工作区\的Google Play-services_lib\BIN \谷歌播放-services_lib.jar' HBuddy构建路径构建路径问题
说明资源路径位置类型在解决构建路径错误之前无法构建项目HBuddy Unknown Java Problem
我已经在Extras中安装了Google Play服务 

android google-api android-maps android-mapview google-maps-android-api-2
我在我的android应用程序中添加了一个mapview.我在清单中使用了正确的设置,现在我遇到了问题.当我去我有地图的地方时,它只显示画布而不显示地图.如果我触摸它只开始加载.即使这样它也没有完全加载.它只加载到一定的水平.如果我继续触摸屏幕,它会不断加载.但即使这样我也无法放大或缩小,甚至无法移动地图.这有解决方案吗?我做错了什么吗?
我的守则
MapView mapView;
GoogleMap map;
mapView = (MapView)view.findViewById(R.id.map);
Bundle savedInstanceState = null;
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
MapsInitializer.initialize(activity);
double lat;
double lon;
lat = Double.parseDouble(theaterDetail.getLatitude());
lon = Double.parseDouble(theaterDetail.getLongitude());
// Updates the location and zoom of the MapView
map.addMarker(new MarkerOptions().position(
new LatLng(lat, lon)).title(theaterDetail.getAddress()));
final LatLng THEATER_POSITION = new LatLng(lat, lon);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(THEATER_POSITION) // Sets the center of the map to
// THEATER_POSITION
.zoom(10) // …Run Code Online (Sandbox Code Playgroud) 当使用最新的谷歌地图API中的MapView时,我收到了内存泄漏,因为MapView正在保持我的活动.
我使用了泄漏金丝雀并且有这种痕迹
D/LeakCanary:*GC ROOT com.google.android.gms.location.internal.ta
D/LeakCanary:*引用com.google.android.gms.location.internal.sa
D/LeakCanary:*引用com.google.maps.api.android.lib6.dvc
D/LeakCanary:*引用com.google.maps.api.android.lib6.d.aj.b
D/LeakCanary:*引用com.google.maps.api.android.lib6.gmm6.cpa
D/LeakCanary:*引用com.google.maps.api.android.lib6.gmm6.cymParent
D/LeakCanary:*引用android.widget.FrameLayout.mParent
D/LeakCanary:*引用com.google.android.gms.maps.MapView.mContext
D/LeakCanary:*泄漏com.myapp.activities.main.AttractionDetailActivity实例
谁看过这个吗?
我正在开发一个地图应用程序.我想在MapView下显示一些视图.我正在使用这个方法:
mapView.setAlpha(0.5f);
Run Code Online (Sandbox Code Playgroud)
mapView没有任何反应.当我尝试将此方法应用于我的按钮时,它工作正常,即使将其应用于mapView的父视图,每个子视图都会透明,除了mapView.
我们怎样才能使mapView透明化?我在这里查看了其他问题,似乎无法找到解决方案.
我们可以使用mapView.getMap()中的一些特殊方法使其透明吗?
android google-maps transparent android-mapview google-maps-android-api-2
在 Jetpack Compose 脚手架中使用抽屉时,可以使用手势打开和关闭它。如果脚手架内容包含 MapView,则无法水平拖动地图。相反,抽屉被打开。
当可滚动行水平拖动(滚动)时,这种情况不会发生,抽屉不会打开。
如何防止用户拖动地图时抽屉打开?当拖动脚手架的其余内容时,该手势应该仍然有效。
不幸的是,用 a 包裹AndroidView并Row不能解决问题,以及使用 ModalDrawer 而不是脚手架。
使用 Compose rc02 和 kotlin 1.5.10 重现的代码(编辑:使用 Compose 1.0.3 和 Kotlin 1.5.30 进行验证):
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Scaffold(
drawerContent = {
Text("Drawer Content")
},
content = {
Column {
Text("Dragging here should open the drawer")
val mapView = rememberMapViewWithLifecycle()
AndroidView({ mapView }, Modifier.fillMaxSize())
}
}
)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
该函数rememberMapViewWithLifecycle() …
android kotlin android-mapview android-jetpack android-jetpack-compose
android-mapview ×10
android ×9
google-maps ×4
overlay ×2
android-maps ×1
api-key ×1
fragment ×1
google-api ×1
ios ×1
kotlin ×1
leakcanary ×1
listener ×1
memory-leaks ×1
mkmapview ×1
transparent ×1
zoom ×1