开发者

Android GEOPOINT error

public void addOverLays(){
    String [] coordinates = {"30.084262490272522","31.33625864982605" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
    double lat = 30.084262490272522, lat2 = 51.5002,lat3=30.084123015403748;
    double log = 31.33625864982605, log2 = -0.1262,log3=31.337149143218994;

    p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
    p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
    p3 = new GeoPoint( (int) (lat3 * 1E6), (int) (log3 * 1E6));
    mapOverlays = mapView.getOverlays();
    drawable = this.getResources().getDrawable(R.drawable.icon);
    drawable2 = this.getResources().getDrawable(R.drawable.pushpin开发者_StackOverflow社区);
    drawable3 = this.getResources().getDrawable(R.drawable.ballon);

    itemizedOverlay = new HelloItemizedOverlay(drawable,this);
    itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);        
    itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);    
    OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
    OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
    OverlayItem over3 = new OverlayItem(p3, "offff", "over3");

    itemizedOverlay.addOverlay(overlayitem);

    mapOverlays.add(itemizedOverlay);

    itemizedOverlay2.addOverlay(over2);
    mapOverlays.add(itemizedOverlay2);

    itemizedOverlay2.addOverlay(over3);
    mapOverlays.add(itemizedOverlay3);

Why can't I add 3 items due to

p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3 = new GeoPoint( (int) (lat3 * 1E6), (int) (log3 * 1E6));

can't make 1E6 & 1e6 what other I have to do?!!


you might have a casting issue, hard to tell. Try using this utility method:

public static GeoPoint calculateGeoPoint(double latitude, double longitude) {
Double latE6 = latitude * 1E6;
Double lngE6 = longitude * 1E6;
return  new GeoPoint(latE6.intValue(), lngE6.intValue());

}

It's worked reliably for me in tested production code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜