我将经纬度作为Google商家信息网址中的字符串获取。现在我想使用获得的坐标在地图上放置一个图钉。有些东西是愚蠢的,因为我试图将字符串解析为GeoPoint的整数,结果显示为0,0所以引脚位于非洲海岸附近。这是我的代码:
int lati5Int, longi5Int;
String latiString = in.getStringExtra(TAG_GEOMETRY_LOCATION_LAT);
String longiString = in.getStringExtra(TAG_GEOMETRY_LOCATION_LNG);
TextView getLatiStringtv.setText(latiString);
TextView getLongiStringtv.setText(longiString);
try {
lati5Int = Integer.parseInt(getLatiStringtv.getText().toString());
longi5Int = Integer.parseInt(getLongiStringtv.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
// shows that the ints are zeros
doubleLatiTV.setText(Integer.toString(lati5Int));
doubleLongiTV.setText(Integer.toString(longi5Int));
//--- GeoPoint---
newPoint = new GeoPoint(lati5Int,longi5Int);
mapController.animateTo(newPoint);
mapController.setZoom(17);
//--- Place pin ----
marker = getResources().getDrawable(R.drawable.malls);
OverlayItem overlaypoint = new OverlayItem(newPoint, "Boing", "Whattsup");
CustomPinpoint customPin = new CustomPinpoint(marker, SMIMap.this);
customPin.insertPinpoint(overlaypoint);
overlayList.add(customPin);
我认为错误在于解析整数:
lati5Int = Integer.parseInt(getLatiStringtv.getText().toString());
longi5Int = Integer.parseInt(getLongiStringtv.getText().toString());
我认为解析会看到坐标中的小数点而且会发疯。那么如何将坐标字符串解析为整数,以便GeoPoint将它们视为正确格式化的坐标,如:30.487263,-97.970799
答案 0 :(得分:2)
GeoPoint
不希望将其视为30.487263,-97.970799。它希望它们为整数30487263,-97970799。就像A.A所说的那样,首先解析为双倍,乘以E6,然后转换为int。
所以可能是这样的:
lati5Int = Double.parseDouble(getLatiStringtv.getText().toString());
latiE6 = (int) (lati5Int*1000000);