2014-06-04 6 views
1

Пожалуйста, помогите мне с программированием на андроид. Я делаю одно приложение android mapsforge и хочу добавить несколько маркеров на карту Android Mapsforge, используя Mysql. Мои данные находятся в базе данных Mysql, и я получаю Json, используя php. Он работает, но проблема заключается в добавлении маркеров. Вот мой код:добавить несколько маркеров на карту Androidforceforce

public void friend_finder(){ 

    try{ 
      HttpClient httpclient = new DefaultHttpClient(); 
      HttpPost httppost = new HttpPost("http://fifauz.com/selectall.php"); 
      HttpResponse response = httpclient.execute(httppost); 
      HttpEntity entity = response.getEntity(); 
      is = entity.getContent(); 

      Log.e("log_tag", "connection success "); 
      Toast.makeText(getApplicationContext(), "Connected", Toast.LENGTH_SHORT).show(); 
     } catch(Exception e){ 
      Log.e("log_tag", "Error in http connection "+e.toString()); 
      Toast.makeText(getApplicationContext(), "Connection fail", Toast.LENGTH_SHORT).show(); 
    } 
    //convert response to string 
    try{  BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); 
      StringBuilder sb = new StringBuilder(); 
      String line = null; 
      while ((line = reader.readLine()) != null) 
      { 
        sb.append(line + "\n"); 
        Intent i = new Intent(getBaseContext(),MainActivity.class); 
        startActivity(i); 
      } 
      is.close(); 

      result=sb.toString(); 
    } 
    catch(Exception e) 
     { 
      Log.e("log_tag", "Error converting result "+e.toString()); 
     } 

    try { 
     JSONArray jArray = new JSONArray(result); 

     for(int i=0;i<jArray.length();i++){ 
      JSONObject json_data = jArray.getJSONObject(i); 
      String name = json_data.getString("Name"); 
      //Double lati = json_data.getDouble("latitude"); 
      // Double longi = json_data.getDouble("longitude"); 
      String lati = json_data.getString("Lati"); 
      String longi = json_data.getString("Long"); 
      String s = name + lati + longi; 
      double lati_d = Double.valueOf(lati.trim()).doubleValue(); 
      double longi_d = Double.valueOf(longi.trim()).doubleValue(); 

      Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); 
      ListOverlay listOverlay = new ListOverlay(); 
      GeoPoint currentLocation = new GeoPoint(lati_d,longi_d); 
      //String marker; 
      //String m = marker + String.valueOf(i); 
      Marker marker = createMarker(R.drawable.person, currentLocation); 

      List<OverlayItem> overlayItems = listOverlay.getOverlayItems(); 
      overlayItems.add(marker); 
      mapView.getOverlays().add(listOverlay); 
     } 

    } catch (Exception e) 
     { 
      Log.e("log_tag", "Error converting result "+e.toString()); 
     } 
    { 
     // TODO: handle exception 
    } 

} 

private Marker createMarker(int resourceIdentifier, GeoPoint geoPoint) { 
    Drawable drawable = getResources().getDrawable(resourceIdentifier); 
    return new Marker(geoPoint, Marker.boundCenterBottom(drawable)); 
} 
+0

Там 3 колонки на столе. Имя. Широта и долгота – user3610339

ответ

2

Вы также можете добавить маркер в mapforge map.

private void createPositionMarker(double paramDouble1, double paramDouble2) 
    final LatLong localLatLong = new LatLong(paramDouble1, paramDouble2); 
    TappableMarker positionmarker = new TappableMarker(R.drawable.destination, localLatLong); 
    mapView.getLayerManager().getLayers().add(positionmarker); 
} 


private class TappableMarker extends Marker{ 
    public TappableMarker(int icon, LatLong localLatLong) { 
      super(localLatLong,AndroidGraphicFactory.convertToBitmap(MainActivity.this.getApplicationContext().getResources().getDrawable(icon)), 
        1*(AndroidGraphicFactory.convertToBitmap(MainActivity.this.getApplicationContext().getResources().getDrawable(icon)).getWidth())/2, 
        -1*(AndroidGraphicFactory.convertToBitmap(MainActivity.this.getApplicationContext().getResources().getDrawable(icon)).getHeight())/2); 
     } 
    } 
Смежные вопросы