开发者

GeoPoint getLatitudeE6() returning -80000000 but getLongitudeE6() returns correct value

Very odd bug that I cant seem to figure out, been looking at it for about an hour trying to refactor to fix this issue, but I cant seem to figure it out, maybe a fresh set of eyes will be able to help me. Listed below is a short bit of code. Any help is appreciated.

Sample KML coordinate string

-98.493095,29.416311,0.000000

KMLHandler.java (I read in kml in a string format)

String[] coords = s.split(",");  
   if ( coords.length == 3 ) {  
      GeoPoint gp = GeoPointUtils.getGeoPoint(co开发者_运维问答ords[0].trim(), coords[1].trim());
      ((Region)overlayItem).addCoordinate(gp);
      Log.d(TAG, "gp.getLat(): " + gp.getLatitudeE6())
      Log.d(TAG, "gp.getLong():" + gp.getLongitudeE6());
    }

GeoPointUtils.java

public static GeoPoint getGeoPoint(double latitude , double longitude) {
   Log.d(TAG, "GeoPointUtils.getGeoPoint(double)");
   Log.d(TAG, "\tIncoming lat -> " + latitude);
   Log.d(TAG, "\tConverted lat -> " + (int) (latitude * 1E6));
   Log.d(TAG, "\tIncoming long -> " + longitude);
   Log.d(TAG, "\tConverted long -> " + (int) (longitude * 1E6));

   return new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
}

public static GeoPoint getGeoPoint(String latitude , String longitude) {
   Log.d(TAG, "GeoPointUtils.getGeoPoint(String)");
   Log.d(TAG, "\tIncoming lat -> " + latitude);
   Log.d(TAG, "\tConverted lat -> " + Double.parseDouble(latitude));
   Log.d(TAG, "\tIncoming long -> " + longitude);
   Log.d(TAG, "\tConverted long -> " + Double.parseDouble(longitude));

   return getGeoPoint(Double.parseDouble(latitude), Double.parseDouble(longitude));
}

Logcat results (sorry for syntax highlighting)

GeoPointUtils.getGeoPoint(String)
   Incoming lat  -> -98.493095
   Converted lat -> -98.493095
   Incoming long ->  29.416311
   Converted long -> 29.416311
GeoPointUtils.getGeoPoint(double)
   Incoming lat  -> -98.493095
   Converted lat -> -98493095
   Incoming long ->  29.416311
   Converted long -> 29416311
gp.getLat(): -80000000
gp.getLong(): 29416311


Wild-ass guess: Latitude is defined as angle north or south of the equator, and thus is restricted to the range -90..+90 degres. Your incoming latitude, -98.5 or so, is bogus, and that may be blowing something up.

Now, assuming that latitude in your code is expressed in some unit other than degrees, I'd say you were hitting some kind of hard fence somewhere.

 You expected gp.getLat(): -98493095
 You got      gp.getLat(): -80000000


Latitude only goes from -90 to +90 degrees. Is that your issue?

If you are trying to plot a point in San Antonio, TX, you switched your lat and long. ;)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜