- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
请告诉我正确的模拟器规范...会不会是模拟器的错误……
我已经尝试通过以下链接
https://www.google.co.in/?gws_rd=cr&ei=iCf5Upm7KsWXrAedkoCoDg#q=marker+cluster+example+in+android
http://karnshah8890.blogspot.in/2013/04/clustering-on-google-map-v2.html
https://developers.google.com/maps/documentation/android/utility/marker-clustering
https://developers.google.com/maps/documentation/android/utility/marker-clustering
http://stackoverflow.com/questions/7447350/android-maps-point-clustering
http://stackoverflow.com/questions/14204554/google-maps-marker-clusters-in-android
https://github.com/twotoasters/clusterkraf/
https://github.com/nodesagency-mobile/Android-Google-Map-V2-Sample
https://github.com/googlemaps/android-maps-utils/tree/master/demo/src/com/google/maps/android/utils/demo/model
https://github.com/Bersh/MarkersCluster/blob/master/res/menu/activity_main.xml
https://github.com/damianflannery/Polaris/blob/clustering/sample/src/com/cyrilmottier/android/polarissample/util/Config.java
http://umut.tekguc.info/en/content/google-android-map-v2-step-step
http://stackoverflow.com/questions/15495171/cluster-markers-in-google-maps-android-v2/15510054#15510054
我正在尝试构建需要标记聚类的应用程序,所以我已经尝试了很多次阅读 Google API 创建演示但每次它显示错误时也提示我该 Web 应用程序正在使用 map API v3 聚类标记我必须使用 map 的 API v2 或 apiv3 构建应用程序的哪个 API 请帮助我,我是 android 的新手或者给我一些我可以找到解决方案的链接
.............................mainactivity class..........................................
package com.example.cluster;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.concurrent.ExecutionException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.example.demo.MarkerClusterizer;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends FragmentActivity {
private ArrayList<MarkerOptions> markers = new ArrayList<MarkerOptions>();
private Bitmap markerImage;
private float oldZoom = 0;
private GoogleMap map;
private static final int INTERVAL = 25;
private LinkedHashMap<Point, ArrayList<MarkerOptions>> clusters;
private final double initLat1 = 40.462740;
private final double initLng1 = 30.039572;
private final double initLat2 = 48.462740;
private final double initLng2 = 35.039572;
private static final int MAP_ZOOM_LEVEL = 4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
markerImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);
map= ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
map.getUiSettings().setMyLocationButtonEnabled(true);
LatLng position = new LatLng(initLat2, initLng2);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(position, MAP_ZOOM_LEVEL));
map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
if (cameraPosition.zoom != oldZoom) {
try {
clusters = MarkerClusterizer.clusterMarkers(map, markers, INTERVAL);
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
oldZoom = cameraPosition.zoom;
}
});
createMarkers(map);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void createMarkers(GoogleMap map) {
double initLat;
double initLng;
initLat = initLat1;
initLng = initLng1;
for (float i = 0; i < 2; i += 0.2) {
LatLng pos = new LatLng(initLat + i, initLng + i);
markers.add(new MarkerOptions().position(pos).icon(BitmapDescriptorFactory.fromBitmap(markerImage)));
}
initLat = initLat2;
initLng = initLng2;
for (float i = 0; i < 2; i += 0.2) {
LatLng pos = new LatLng(initLat + i, initLng);
markers.add(new MarkerOptions().position(pos).icon(BitmapDescriptorFactory.fromBitmap(markerImage)));
}
for (float i = 0; i < 2; i += 0.2) {
LatLng pos = new LatLng(initLat, initLng + i);
markers.add(new MarkerOptions().position(pos).icon(BitmapDescriptorFactory.fromBitmap(markerImage)));
}
}
}
...............................markerclusterizer class...............................
package com.example.demo;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.concurrent.ExecutionException;
import android.graphics.Point;
import android.os.AsyncTask;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.model.MarkerOptions;
public class MarkerClusterizer {
private static GoogleMap map;
private static int interval;
private static final int DEFAULT_INTERVAL = 25;
public static LinkedHashMap<Point,ArrayList<MarkerOptions>>clusterMarkers(GoogleMap googleMap, ArrayList<MarkerOptions> markers) throws ExecutionException, InterruptedException {
return clusterMarkers(googleMap, markers, DEFAULT_INTERVAL);
}
@SuppressWarnings("unchecked")
public static LinkedHashMap<Point, ArrayList<MarkerOptions>> clusterMarkers(GoogleMap googleMap, ArrayList<MarkerOptions> markers, int i) throws ExecutionException, InterruptedException {
map=googleMap;
interval=i;
Projection projection=map.getProjection();
LinkedHashMap<MarkerOptions, Point> points=new LinkedHashMap<MarkerOptions, Point>();
for(MarkerOptions markerOptions:markers){
points.put(markerOptions, projection.toScreenLocation(markerOptions.getPosition()));
markerOptions.title("");
}
map.clear();
CheckMarkersTask checkMarkersTask=new CheckMarkersTask();
checkMarkersTask.execute(points);
return checkMarkersTask.get();
}
private static class CheckMarkersTask extends AsyncTask<LinkedHashMap<MarkerOptions, Point>, Void, LinkedHashMap<Point, ArrayList<MarkerOptions>>> {
private double findDistance(float x1, float y1, float x2, float y2) {
return Math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
}
@Override
protected LinkedHashMap<Point, ArrayList<MarkerOptions>> doInBackground(LinkedHashMap<MarkerOptions, Point>... params) {
LinkedHashMap<Point, ArrayList<MarkerOptions>> clusters = new LinkedHashMap<Point, ArrayList<MarkerOptions>>();
LinkedHashMap<MarkerOptions, Point> points = params[0];
for (MarkerOptions markerOptions : points.keySet()) { //go thru all markers
Point point = points.get(markerOptions);
double minDistance = -1; //Currently found min distance. This need for finding nearest point.
Point nearestPoint = null; //Currently found nearest point
double currentDistance;
for (Point existingPoint : clusters.keySet()) { //try to find existing cluster for current marker
currentDistance = findDistance(point.x, point.y, existingPoint.x, existingPoint.y);
if ((currentDistance <= interval) && ((currentDistance < minDistance) || (minDistance == -1))) {
minDistance = currentDistance;
nearestPoint = existingPoint;
}
}
if (nearestPoint != null) {
clusters.get(nearestPoint).add(markerOptions);
} else {
ArrayList<MarkerOptions> markersForPoint = new ArrayList<MarkerOptions>();
markersForPoint.add(markerOptions);
clusters.put(point, markersForPoint);
}
}
return clusters;
}
@Override
protected void onPostExecute(LinkedHashMap<Point, ArrayList<MarkerOptions>> clusters) {
for (Point point : clusters.keySet()) {
ArrayList<MarkerOptions> markersForPoint = clusters.get(point);
MarkerOptions mainMarker = markersForPoint.get(0);
int clusterSize = markersForPoint.size();
if (clusterSize > 1) {
mainMarker.title(Integer.toString(clusterSize));
}
map.addMarker(mainMarker);
}
}
}
}
![..............activity_main.xml...............................................
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>t
</RelativeLayout>
..................manifest.xml................................................
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cluster"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission
android:name="com.example.cluster.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.demo.permission.MAPS_RECEIVE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.cluster.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDqFw-lJjvppil-ixpHjBolINPqJO2b83Q" />
</application>
</manifest>][1]
最佳答案
do plz tell me the right emulator specification
我真的很喜欢 GenyMotion
来测试我的 android 应用程序。它比 Android 提供的要好得多。
从 here 下载 Genymotion然后添加你想要的模拟器
error msg doesn't support opengles on device
对于真实设备,请确保您的设备支持您的 map 所需的 OpenGL ES 版本 2。
对于标记集群,您可以阅读文档 here .
关于android - 如何使用 map apiv2 或 map api v3 在 android 中做 markererclusterer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21850572/
我正在尝试从一个 map 的 map 的 map 的 map 的 map 的 map 的 map 的 map 的 map 的 map 的 map 的 map 的 map 的 map 的 map 的 m
我是 Haskell 的新手,我认为函数 map map和 map.map在 Haskell 中是一样的。 我的终端给了我两种不同的类型, (map.map) :: (a -> b) -> [[a]
我的目标是创建一个 map 的 map ,这样我就可以通过它的键检索外部 map 的信息,然后通过它们的键访问它的“内部” map 。 但是,当我得到每个内部映射时,我最初创建的映射变成了一个对象,我
如何使用 Java8 编写以下代码? for (Entry> entry : data.entrySet()) { Map value = entry.getValue(); if (valu
我有覆盖整个南非的图片。它们为Tiff格式,并已将坐标嵌入其中。我正在尝试拍摄这些图像(大约20张图像),并将它们用作我的iPhone应用程序中的地图叠加层。我的问题在于(准确地)将地图切成图块。 我
所以我有 2 std::map s >一个是“旧的”,一个是“新的”,我想知道哪些文件被删除了,这样就能够遍历差异并对 shared_ptr 做一些事情。这样的事情可能吗?如何做到? 最佳答案 虽然
是否可以将当前查看的 google.maps.Map 转换为静态图像链接,以便我可以获取图像并将其嵌入到 PDF 中? 我在 map 上添加了一些带有自定义图标的标记,所以我不确定这是否真的可行。 如
你能帮我吗 Java Streams ? 从标题可以看出我需要合并List>>进入Map> . 列表表示为List>>看起来像: [ { "USER_1":{
对于 idAndTags 的第二个条目,内部映射被打乱,但第一个条目则不然 第一次接近! for (Map.Entry> entryOne : idAndTags.entrySet()) {
我将从我的代码开始,因为它应该更容易理解我想要做什么: @function get-color($color, $lightness) { @return map-get(map-get($col
我过去曾在许多网站上使用过 Google map ,但遇到了以前从未遇到过的问题。 map 窗口正在显示,但它只显示左上角的 map 片段,以及之后的任何内容(即使我在周围导航时),右侧也不会加载任何
众所周知,这些 map ,无论是常规街道 map 还是卫星 map ,在中国的特定地区都无法正确排列。那么哪个 map 排列正确,是卫星 map 还是默认街道 map ?一些网站表明卫星 map 是正
在拖尾事件之后,我面临着获取此处 map 中的 map 边界的问题。我需要新的经纬度来在新更改的视口(viewport)中获取一些项目/点。我只是想在拖动结束时获得谷歌地图map.getBounds(
我想做的是通过 ajax API 显示以英国邮政编码为中心的小型 bing 生成 map 。我相信这是可能的;我在 Bing map 文档中找不到如何将英国邮政编码转换为可以插入 map Ajax 控
我有一个 List我想转换成的 e Map>其中外部字符串应为“Name”,内部字符串应为“Domain”。 Name Id Domain e(0) - Emp1, 1, Insuran
我的第 2 部分:https://stackoverflow.com/questions/21780627/c-map-of-maps-typedef-doubts-queries 然后我继续创建 I
是否可以在 1 行中使用 Java8 编写以下所有 null 和空字符串检查? Map> data = new HashMap<>(holdings.rowMap()); Set>> entrySet
我正在审查一个项目的旧代码,并使用 Map 的 Map 的 Map 获得了如下数据结构(3 层 map ): // data structure Map>>> tagTree
这可能是一种不好的做法,但我还没有找到更好的解决方案来解决我的问题。所以我有这张 map // Map>> private Map>> properties; 我想初始化它,这样我就不会得到 Null
我们在 JDK 1.7 中使用 HashMap,我在使用 SonarQube 进行代码审查时遇到了一些问题。 请考虑以下示例: public class SerializationTest imple
我是一名优秀的程序员,十分优秀!