2012-03-30 96 views
0

從json feed獲取所有緯度和經度並在mapview中添加所有內容。我開了不同的標記,但所有的點都顯示在海中。這是我的代碼。誰能幫助我,請地圖緯度和經度在android中顯示在海中?

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; 
} 

}

回答

2

@harish - 你得到緯度經度&像51.509998321533,-0.12999999523163 但是在android系統的GeoPoint只接受int類型。 現在創造將採取這些值& restric他們最多6個小數點&你會得到結果,你想 功能就會像

double roundTwoDecimals(double d){ 
     DecimalFormat twoDForm = new DecimalFormat("#.######"); 
     return Double.valueOf(twoDForm.format(d)); 
    } 

這種方式,您將得到雙重價值&然後用10E6乘以它的功能&你會得到INT,你需要創建GeoPoints使用..

+0

@ sandip沒有得到 – harish 2012-03-30 08:21:15

+1

@harish - GeoPoint構造函數只接受int對嗎?現在你知道整數限制嗎?如果您採用6位以上的小數點,它將與int限制交叉,因此地圖上的地理位置顯示在錯誤的位置。你有沒有試過我建議的? &isi t working? – 2012-03-30 09:01:18

0

,如果它有差別,但行了,我不suere

latitudeAry.add(c.getString(TAG_lONGITUDE).toString()); 

在longITUDE中有一個小寫的L

相關問題