从json feed获取所有纬度和经度并在mapview中添加所有内容。我得到了不同的标记。但所有的点都在海中展示。这是我的代码。请有人帮帮我吗
MapItemizedOverlay itemizedoverlay;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
url = "http://dentonsweb.com/app/html/android/get.php?what=Hotels&lat=51.507222&lon=-0.1275&pg=0";
System.out.println("url is "+url);
Jsonfunctions jParser = new Jsonfunctions();
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
results = json.getJSONArray(TAG_RESULTS);
// looping through All Contacts
for (int i = 0; i < results.length(); i++) {
JSONObject c = results.getJSONObject(i);
id = c.getString(TAG_ID);
name = c.getString(TAG_NAME);
System.out.println("name is " + name);
adress = c.getString(TAG_ADRRESS);
latitude = c.getString(TAG_LATITUDE);
latitudeAry.add(c.getString(TAG_LATITUDE).toString());
longitude = c.getString(TAG_lONGITUDE);
latitudeAry.add(c.getString(TAG_lONGITUDE).toString());
distance = c.getString(TAG_DISTANCE);
image = c.getString(TAG_IMAGE);
phone = c.getString(TAG_TELEPHONE);
telphonenumberAry
.add(c.getString(TAG_TELEPHONE).toString());
NameAry.add(c.getString(TAG_NAME).toString());
resourceAry.add(new ResourceClass(point,id, name, adress,image,
distance, latitude, longitude, phone));
System.out.println("arraooosdospodpsodps " + resourceAry);
}
} catch (JSONException e) {
e.printStackTrace();
}
mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
mc = mapView.getController();
listOfOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(
R.drawable.pin);
itemizedoverlay = new MapItemizedOverlay(drawable,mapView);
for (int i = 0; i < resourceAry.size(); i++) {
// latitude = resourceAry.get(i).getLatitude();
System.out.println("latitude is " + latitude);
String latitude = resourceAry.get(i).getLatitude();
String longitude = resourceAry.get(i).getLongitude();
// longitude = resourceAry.get(i).getLongitude();
String name = resourceAry.get(i).getName();
System.out.println("Name is" + name);
String adress = resourceAry.get(i).getAdress();
if (!latitude.equals("") && !longitude.equals("")) {
Double latitude_next = Double.parseDouble(latitude);
Double longitude_next = Double.parseDouble(longitude);
point = new GeoPoint((int) (latitude_next * 1E6),
(int) (longitude_next * 1E6));
System.out.println("point is " + point);
overlayitem = new OverlayItem(point,resourceAry.get(i).getName(),resourceAry.get(i).getAdress());
// System.out.println( " spanned text: " +
// Html.fromHtml(Texte));
itemizedoverlay.addOverlay(overlayitem);
listOfOverlays.add(itemizedoverlay);
}
}
mc.animateTo(point);
mc.setZoom(13);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
答案 0 :(得分:2)
@harish - 你得到纬度和经度如51.509998321533,-0.12999999523163 但在android中,geopoint只接受int值。 现在创建一个将采用这些值和&amp;将它们限制在6个小数点以内你会得到你想要的结果 功能就像
double roundTwoDecimals(double d){
DecimalFormat twoDForm = new DecimalFormat("#.######");
return Double.valueOf(twoDForm.format(d));
}
通过这种方式,您将获得双倍价值&amp;然后乘以10E6&amp;你将获得在创建GeoPoints时需要使用的int ..
答案 1 :(得分:0)
我不确定它是否会产生影响但行
latitudeAry.add(c.getString(TAG_lONGITUDE).toString());
在lONGITUDE中有一个小写的L