Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从google map v2获取android中的连接工厂客户端、标记群集_Android_Google Maps_Android Fragments_Android Maps V2 - Fatal编程技术网

无法从google map v2获取android中的连接工厂客户端、标记群集

无法从google map v2获取android中的连接工厂客户端、标记群集,android,google-maps,android-fragments,android-maps-v2,Android,Google Maps,Android Fragments,Android Maps V2,它显示了坐标,但没有在地面显示地图,无法连接工厂客户,有人能帮我吗。。。。。。。我从GitHub获取了这段代码,作为参考,请帮助我 雄激素样MAPCLUSTERING活性 . package com.needin; import android.os.Bundle; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.needin.mapviewclus

它显示了坐标,但没有在地面显示地图,无法连接工厂客户,有人能帮我吗。。。。。。。我从GitHub获取了这段代码,作为参考,请帮助我 雄激素样MAPCLUSTERING活性

.
package com.needin;

import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.needin.mapviewcluster.CMapView;
import com.needin.mapviewcluster.ClusteredGeoPoint;

import java.util.ArrayList;
import java.util.List;

public class AndroidMapClusteringActivity extends MapActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        CMapView mapView = new CMapView(this, "AIzaSyDvrqa1xm0mqwmCz74RYZPR7X1vifvXwJI");
        setContentView(mapView);
        mapView.setPoints(generateDummyPoints()).setMaxPoints(20);
    }

    private List<GeoPoint> generateDummyPoints() {
        List<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
        for (int i = -130; i < 130; i += 40) {
            for (int j = -130; j < 130; j += 40) {
                geoPoints.add(ClusteredGeoPoint.GetPointFromDouble(i, j));
            }
        }
        return geoPoints;
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}
.........................ClusteredGeoPoint..............................................
package com.needin.mapviewcluster;

import com.google.android.maps.GeoPoint;

/**
 * Created with ADT
 * User: Vaibhav
 * Date: 11/02/14
 * Time: 3:29 PM
 * 
 */
public class ClusteredGeoPoint extends GeoPoint {
    private int weight = 1;

    public int getWeight() {
        return weight;
    }

    public float getRadius(){
        if(weight==1){
            return 10;
        }else{
            return 10 + (float)Math.sqrt(weight);
        }
    }

    public GeoPoint getMainPoint() {
        return mainPoint;
    }
    public boolean isClustered(){
        return !equals(mainPoint) ;
    }

    private GeoPoint mainPoint;
    public ClusteredGeoPoint(int lat, int lng, int weight,GeoPoint mainPoint) {
        super(lat,lng);
        this.weight = weight;
        this.mainPoint=mainPoint;
    }
    public ClusteredGeoPoint(GeoPoint point, int weight) {
        super(point.getLatitudeE6(),point.getLongitudeE6());
        this.weight = weight;
    }

    public static GeoPoint GetPointFromDouble(double lat, double lng) {
        return new GeoPoint((int) (lat * 1e6), (int) (lng * 1e6));
    }
}
..................................CMapView.......................................
import android.content.Context;

import android.graphics.*;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

import java.util.ArrayList;
import java.util.List;

public class CMapView extends MapView {

    private List<ClusteredGeoPoint> geoPoints = new ArrayList<ClusteredGeoPoint>();
    private List<GeoPoint> originalPoints = new ArrayList<GeoPoint>();
    private int maxPoints=10;
    private static final String TAG = "CMapView";
    private MyOverlay overlay = new MyOverlay();

    public CMapView(final Context context, String apiKey) {
        super(context, apiKey);
        setClickable(true);
        setBuiltInZoomControls(true);
        getOverlays().add((overlay));
    }

    public CMapView setPoints(List<GeoPoint> geoPoints) {
        originalPoints = geoPoints;
        refreshPoints();
        invalidate();
        return this;
    }
    public CMapView setMaxPoints(int maxPoints) {
        this.maxPoints = maxPoints;
        refreshPoints();
        invalidate();
        return this;
    }

    public void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        refreshPoints();
    }

    private List<GeoPoint> getVisiblePoints(List<GeoPoint> geoPoints) {
        ArrayList<GeoPoint> visiblePoints = new ArrayList<GeoPoint>();
        for (GeoPoint point : geoPoints) {
            if (isCurrentLocationVisible(point)) {
                visiblePoints.add(point);
            }
        }
        return visiblePoints;
    }

    private boolean isCurrentLocationVisible(GeoPoint point) {
        Rect currentMapBoundsRect = new Rect();
        Point currentDevicePosition = new Point();

        getProjection().toPixels(point, currentDevicePosition);
        getDrawingRect(currentMapBoundsRect);

        return currentMapBoundsRect.contains(currentDevicePosition.x,
                currentDevicePosition.y);

    }

    private static double findDistance(float x1, float y1, float x2, float y2) {
        return Math.sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
    }

    private void refreshPoints() {
        this.geoPoints = DVMClusterer.getClusteredPoints(getVisiblePoints(originalPoints), maxPoints);
    }

    private class MyOverlay extends Overlay {

        private Point pointC = new Point();
        private Point pointO = new Point();
        private Paint solidPaint = new Paint();
        private Paint redPaint = new Paint();
        private Paint textPaint = new Paint();

        public MyOverlay() {
            solidPaint.setColor(Color.BLUE);
            solidPaint.setAntiAlias(true);
            redPaint.setColor(Color.RED);
            textPaint.setColor(Color.WHITE);
            textPaint.setTextSize(22);
        }

        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
            Projection projection = mapView.getProjection();
            for (ClusteredGeoPoint geoPoint : geoPoints) {
                projection.toPixels(geoPoint, pointC);
                projection.toPixels(geoPoint.getMainPoint(), pointO);
                double radius = findDistance(pointC.x, pointC.y, pointO.x, pointO.y);
                if (geoPoint.isClustered()) {
                    solidPaint.setAlpha(50);
                    canvas.drawCircle(pointC.x, pointC.y, 10 + (float) radius / 2, solidPaint);
                    canvas.drawText(geoPoint.getWeight() + "", pointC.x, pointC.y, textPaint);
                } else {
                    solidPaint.setAlpha(255);
                    canvas.drawCircle(pointC.x, pointC.y, 10 + (float) radius / 2, solidPaint);
                }
            }
            return super.draw(canvas, mapView, shadow, when);
        }

    }


}
...............................DVMClusterer..............................................
import android.util.Log;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.tomgibara.cluster.gvm.intgr.IntClusters;
import com.tomgibara.cluster.gvm.intgr.IntResult;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with ADT.
 * User: Vaibhav
 * Date: 11/02/14
 * Time: 3:30 PM
 * To change this template use File | Settings | File Templates.
 */
public class DVMClusterer {
    private static final String TAG = "DVMClusterer";

    public static List<ClusteredGeoPoint> getClusteredPoints(List<GeoPoint> geoPoints, int maxClusters) {

        int[] xs = new int[2];
        IntClusters<GeoPoint> clusters = new IntClusters<GeoPoint>(2, maxClusters);

        //This is too slow!
        for (GeoPoint point : geoPoints) {
            xs[0] = point.getLongitudeE6();
            xs[1] = point.getLatitudeE6();
            clusters.add(1, xs, point);
        }

        List<ClusteredGeoPoint> clusteredPoints = new ArrayList<ClusteredGeoPoint>();

        List<IntResult<GeoPoint>> results = clusters.results();
        for (IntResult<GeoPoint> clusteredPoint : results) {

            Log.i(TAG, "lng= "
                    + clusteredPoint.getCoords()[0] + " lat= "
                    + clusteredPoint.getCoords()[1]
                    + " weight= "
                    + clusteredPoint.getMass()
                    + "variance = " + clusteredPoint.getKey().getLongitudeE6());

            clusteredPoints.add(
                    new ClusteredGeoPoint(
                            clusteredPoint.getCoords()[1],
                            clusteredPoint.getCoords()[0],
                            clusteredPoint.getMass(),
                            clusteredPoint.getKey())
            );

        }
        return clusteredPoints;
    }

    private static List<GeoPoint> getVisiblePoints(MapView mapView) {
        return new ArrayList<GeoPoint>();
    }

}

..........................main.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" >

   <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         class="com.google.android.gms.maps.SupportMapFragment"
         />

</LinearLayout>
.....................manifest.xml...........................................
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.needin.mapclustering"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:debuggable="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name="com.needin.AndroidMapClusteringActivity"
            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="AIzaSyDvrqa1xm0mqwmCz74RYZPR7X1vifvXwJI" />
    </application>

    <uses-permission android:name="android.permission.INTERNET" />
    <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="com.needin.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.needin.mapviewcluster.permission.MAPS_RECEIVE" />

</manifest>
或者还有一件事,我建议每次创建应用程序时,我们都必须为不同的应用程序重新生成api密钥,并使用它们的包名