使用2个简单的活动.第一个Activity只包含一个按钮来启动第二个包含地图的Activity:
主要活动:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void goToMap(View view){ //This is just the onClick method for the button
Intent intent=new Intent( this, BigMapTest.class);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
地图活动:
public class BigMapTest extends FragmentActivity {
SupportMapFragment mapFragment;
GoogleMap map;
@Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.travel_diary_big_map);
mapFragment=(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.big_map);
map=mapFragment.getMap();
}
Run Code Online (Sandbox Code Playgroud)
地图活动的XML布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/big_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
Run Code Online (Sandbox Code Playgroud)
现在当我运行这段代码时,按下按钮移动到带有地图的Activity,然后按回去进入第一个活动...然后重复这个过程,我可以看到每次堆的大小都在增加,直到达到这是限制,然后开始钳制.如果你用地图(即缩放)混乱一点,我可以在这一点上获得一个OOM异常.
01-25 16:10:13.931:D/dalvikvm(21578):GC_FOR_ALLOC释放1898K,7%空闲45859K/49187K,暂停204ms …
android google-maps-android-api-2 supportmapfragment android-maps-v2
基本上在向地图添加标记时,它会返回新标记,您可以像这样从中获取标记ID
Marker m = map.addMarker(new MarkerOptions()
.position(new LatLng(lat,lon)));
String id = m.getId();
Run Code Online (Sandbox Code Playgroud)
如果有很多标记并且你只想删除一个标记,有没有办法通过它的id获取标记?
我尝试使用Intellij IDEA 12运行Google地图.
我已经尝试过建议:
等等.但不幸的是,这对我不起作用.
我的配置:
1)真正的设备htc wildefire s,android 2.3.5
2) 
3)AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.ergeslab.TransportScheduleYaroslavl"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0">
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<permission
android:name="ru.ergeslab.TransportScheduleYaroslavl.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="ru.ergeslab.TransportScheduleYaroslavl.permission.MAPS_RECEIVE"/>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<application android:label="@string/app_name">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_KEY"/>
<uses-library android:name="com.google.android.maps" />
<activity android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
4) MainActivity: …
android google-maps noclassdeffounderror google-maps-android-api-2
使用Google Map API V3时,我可以通过以下方式添加自定义属性:
var marker = new google.maps.Marker({
position: userLocation,
map: myGoogleMap,
animation: google.maps.Animation.DROP,
icon: avatar,
title: userName,
customProperty1: bla,
customProperty2: bla,
customProperty3: bla,
...
Run Code Online (Sandbox Code Playgroud)
});
我想知道我是否可以为API V2 Android做同样的事情,我想这样做的原因是每个标记的每个信息窗口都需要知道该标记的一些信息.而我正在努力实现以下render功能:
private void render(Marker marker, View view) {
int badge = R.drawable.android_face;
if (marker.customProperty)
//here I need to know this property to decide which image to use
badge = R.drawable.bla;
((ImageView) view.findViewById(R.id.badge))
.setImageResource(badge);
}
Run Code Online (Sandbox Code Playgroud) 我在姜饼上打开抽屉时有这个问题,后面是google map v2.应该在屏幕后面的地图是最重要的.
现在我可以通过在抽屉打开时隐藏地图并在关闭时显示它来绕过这个但是我正在寻找更优雅的解决方案,如果有人提出任何?

我正在开发一个用于农业目的的Glebe取样申请.在那个用户可以通过点击地图来选择一个Glebe,这将根据点击的数量创建一个多边形.我能够创建该多边形并能够获得多边形的区域.但现在我需要把它分成相等的区域.
例如,如果多边形的面积是50平方公尺,那么它将被分成50个1平方公尺的区域.Agri Precision App已经完成了相同的功能.找到下面的图像.我需要将多边形划分为与下图相同,并显示其中的点.

为了获得Area,我正在使用Google Map Utilty Lib它也有一个算法用于网格聚类.我想要像上面的图像一样.在上图中,它们按每5公顷划分面积.由于所有区域都是85公顷,因此应显示的总分数为17.这就是它的工作原理.
所以我的问题是:
如何根据Map上多边形的面积找到这些点,以便我可以在Map上绘制这些点?
看这个插图:

我想知道的是:
如果您能使用Google Maps API V2为我提供Java代码示例或专门针对Android的代码示例,我更愿意
java android area latitude-longitude google-maps-android-api-2
MapView的getMap()方法可以返回null.我知道这是Google的预期行为.
有人可以提供关于何时以及在何种情况下该方法返回null 的明确描述getMap()?
我知道如果Google服务在给定设备上不可用,getMap()则会返回null.这种可能性相对较好地记录在案.我更关注模糊的其他情况,即使在设备上安装Google服务,getMap()仍然可以返回null.
到目前为止,我的假设是底层地图系统有一些初始化,在此期间您的代码可能会执行并获得一个空地图.
我的假设是否正确?
在Activity或Fragment生命周期中是否有任何特定的位置我们可以明确地获得非null GoogleMap(如果我们假设安装了Google Services IS)?
我提出这个问题的目的是防止if(mapView.getMap() != null)在我的代码中散布一连串的支票.此外,这个问题似乎依然拿出定期在这里StackOverflow上,我想看看我们是否能够割肉出局的背后究竟是怎么回事用真情MapView和getMap()
我的应用程序中存在巨大的内存问题.我正在使用谷歌地图api v2 ClusterManager和自定义标记.我markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));根据其类别通过调用为每个标记提供图像.问题是:在几次屏幕旋转后,我的应用程序因OOM错误而崩溃:
05-14 11:04:12.692 14020-30201/rokask.rideabike E/art? Throwing OutOfMemoryError "Failed to allocate a 4194316 byte allocation with 1627608 free bytes and 1589KB until OOM"
05-14 11:04:12.722 14020-30201/rokask.rideabike E/AndroidRuntime? FATAL EXCEPTION: GLThread 19179
Process: rokask.rideabike, PID: 14020
java.lang.OutOfMemoryError: Failed to allocate a 4194316 byte allocation with 1627608 free bytes and 1589KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:939)
at android.graphics.Bitmap.createBitmap(Bitmap.java:912)
at android.graphics.Bitmap.createBitmap(Bitmap.java:879)
at com.google.maps.api.android.lib6.gmm6.n.c.i.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.c.l.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.c.l.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.c.l.b(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud) android bitmap out-of-memory markerclusterer google-maps-android-api-2
我想在我的Android应用程序中显示两个位置之间的行车路线.我想在路段之上绘制路线.
堆栈溢出本身有几个答案,所有这些都使用相同的方法.使用Google Directions API获取从起点到目的地的路线,并在返回的点上绘制折线.以下是使用此方法的一些答案.
但是,上述方法的问题是,当道路不直时,黎明死记硬背并不总是在道路上,因为方向API只返回您需要从一条道路转向另一条道路的点(在交叉点处).它没有在同一道路段的弯道中给出点数细节.因此,当我在道路有很多弯道的区域使用上述方法时,几乎总是绘制的路线不在路段之上.
我找到了这个答案,它使用javascript API做我需要做的事情.在这个解决方案中,绘制的路线很好地遵循道路,类似于谷歌地图Android应用程序.有人知道这是否可以在Android应用程序中实现?
谷歌地图Android应用程序可以很好地绘制从一个点到另一个点的路线,保持路线在道路上.有谁知道谷歌地图是如何做到这一点的?它是否使用任何其他未公开的API?