2013-10-29 25 views
1

我想在Google地圖上顯示多個標記。我的latlng從Parse數據庫中提取,但我無法看到標記 ,而我的第二個問題是我想要顯示帶有標記的Restaurant Name的標題以及如何執行此操作。 這是我的代碼無法在google上查看多個標記地圖

 
private class putMarker extends AsyncTask> { 

     @Override 
     protected ArrayList doInBackground(Void... params) { 
      // TODO Auto-generated method stub 
      try { 

       Toast.makeText(getApplicationContext(), 
         longitude + " " + latitude, Toast.LENGTH_SHORT).show(); 

       ParseQuery query = new ParseQuery(
         "Details"); 
       ParseGeoPoint myGeoPiont = new ParseGeoPoint(latitude, 
         longitude); 
       query.whereNear("location", myGeoPiont); 
       query.setLimit(10); 
       ob = query.find(); 
       for (ParseObject resObj : ob) { 
        ParseGeoPoint location = resObj 
          .getParseGeoPoint("location"); 
        restaurantName = (String) resObj.get("RestaurantName"); 
        LatLng resLatLng = new LatLng(location.getLatitude(), 
          location.getLongitude()); 
        Toast.makeText(getApplicationContext(), 
          restaurantName, Toast.LENGTH_SHORT) 
          .show(); 
        PiontList.add(resLatLng); 
       } 

      } catch (Exception e) { 
       // TODO: handle exception 
      } 
      return PiontList; 
     } 
     protected void onPostExecute(ArrayList latlngList) { 
      for(LatLng res: latlngList) 
      { 
       MarkerOptions markerOptions = new MarkerOptions(); 
       markerOptions.position(res); 
       markerOptions.icon(BitmapDescriptorFactory 
         .defaultMarker(BitmapDescriptorFactory.HUE_GREEN)); 
       googleMap.addMarker(markerOptions); 
      } 
     } 

    } 

請幫我。

+0

您無法更新從'doInbackground UI ()'。刪除烤麪包 – Raghunandan

+0

非常感謝你,我現在可以看到標記,但我怎麼可以發送latlng和字符串到我的onPostExecute()方法。 – user1659731

+0

您可以使用字符串生成器並返回結果。返回的結果是一個參數onPostexecute – Raghunandan

回答

0

這可能是由於onPostExecute()中googleMap對象的不可達性。 請確保googleMap是全局聲明的。

如果可能的話,請粘貼整個代碼更好的評價

0

試試這個

// Create lat long points 
Latlng[] point_new = new LatLng[8]; 
       point_new[0] = new LatLng(31.5301843, 74.3207487); 
       point_new[1] = new LatLng(31.5214693,74.3236027); 
       point_new[2] = new LatLng(31.5194393, 74.3257327); 
       point_new[3] = new LatLng(31.4942166, 74.3004533); 
       point_new[4] = new LatLng(31.4864646, 74.2911203); 
       point_new[5] = new LatLng(31.4803596, 74.2787933); 
       point_new[6] = new LatLng(31.4764716, 74.2638203); 
       point_new[7] = new LatLng(31.4775236, 74.2628873); 
// Add markers 

for (int i = 0; i < point_new.length; i++) { 
        MarkerOptions markerOptions = new MarkerOptions() 
          .position(point_new[i]); 
        marker = mMap.addMarker(markerOptions); 
        marker.setTitle("Points"); 
        marker.setSnippet("Distance = 9.6 km, Time = 20 minute/s"); 
        marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.p)); 
} 

//將相機與縮放級別去年9點

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(point_new[7], 9)); 
相關問題