Refresh Maps

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Refresh Maps

Postby mute » Mon May 31, 2010 6:12 pm

Hello, I have a problem with MapAtivity, trying to put a marker on the map dynamically, the problem is map refreshed in every seconds and when I press the "Back" button nothing happens.
where is my error, how I stop this refreshing.
p.s. sorry for my english

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package sd.mb;
  2.  
  3. import java.util.List;
  4.  
  5. import org.json.JSONArray;
  6. import org.json.JSONException;
  7. import org.json.JSONObject;
  8.  
  9. import android.app.AlertDialog;
  10. import android.content.Context;
  11. import android.content.DialogInterface;
  12. import android.content.Intent;
  13. import android.graphics.drawable.Drawable;
  14. import android.os.Bundle;
  15. import android.view.KeyEvent;
  16. import android.view.inputmethod.InputMethodManager;
  17.  
  18. import com.google.android.maps.GeoPoint;
  19. import com.google.android.maps.MapActivity;
  20. import com.google.android.maps.MapController;
  21. import com.google.android.maps.MapView;
  22. import com.google.android.maps.Overlay;
  23. import com.google.android.maps.OverlayItem;
  24.  
  25.  
  26. public class MyMap extends MapActivity  {
  27.        
  28.         private MapView mapView;
  29.        
  30.         List<Overlay> mapOverlays;
  31.         Drawable drawable;
  32.         ItemizedOverlay iOverlay;
  33.  
  34.  
  35.     public void onCreate(Bundle savedInstanceState)
  36.     {
  37.         super.onCreate(savedInstanceState);
  38.         setContentView(R.layout.map);
  39.        
  40.         //get data from web
  41.         Bundle b = this.getIntent().getExtras();
  42.         String mapData = b.getString("json");
  43.        
  44.         mapView = (MapView) findViewById(R.id.mymap);
  45.         mapView.setBuiltInZoomControls(true);
  46.        
  47.         GeoPoint pt = new GeoPoint((int) (b.getDouble("mylat") * 1E6), (int) (b.getDouble("mylng") * 1E6));
  48.         MapController mc = mapView.getController();
  49.         mc.setCenter(pt);
  50.         mc.setZoom(15);
  51.        
  52.         //mapOverlays = mapView.getOverlays();
  53.        
  54.         try {
  55.                         JSONArray jsonArray = new JSONArray(mapData);
  56.                        
  57.                         for (int i=0; i < jsonArray.length(); i++ ) {
  58.                                 JSONObject p = jsonArray.getJSONObject(i);
  59.                                
  60.                                 //parse lat and lng from json
  61.                                 double lat = Double.parseDouble(p.getString("lat"));
  62.                     double lng = Double.parseDouble(p.getString("lng"));
  63.                    
  64.                     //make icon
  65.                     drawable = getIcon(p.getInt("bankid"));
  66.                     iOverlay = new ItemizedOverlay(drawable, this);
  67.                        
  68.                         GeoPoint point = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
  69.                     OverlayItem overlayitem = new OverlayItem(point, p.getString("bankname"), p.getString("baddress"));
  70.                      
  71.                     iOverlay.addOverlay(overlayitem);
  72.                     mapView.getOverlays().add(iOverlay);
  73.                                
  74.                         }
  75.                        
  76.                         drawable = getIcon(0);
  77.             iOverlay = new ItemizedOverlay(drawable, this);
  78.                
  79.                 GeoPoint point = new GeoPoint((int) (b.getDouble("mylat") * 1E6), (int) (b.getDouble("mylng") * 1E6));
  80.             OverlayItem overlayitem = new OverlayItem(point, "", "");
  81.              
  82.             iOverlay.addOverlay(overlayitem);
  83.             mapView.getOverlays().add(iOverlay);
  84.                        
  85.                        
  86.                 } catch (JSONException e) {
  87.                         e.printStackTrace();
  88.                 }
  89.     }
  90.  
  91.     @Override
  92.     protected boolean isRouteDisplayed() {
  93.         return false;
  94.     }
  95.    
  96.    
  97.     private Drawable getIcon(int bankid) {
  98.        
  99.         switch( bankid) {
  100.                
  101.                 case 1 : return this.getResources().getDrawable(R.drawable.bank_1);
  102.                 case 2 : return this.getResources().getDrawable(R.drawable.bank_2);
  103.                 case 3 : return this.getResources().getDrawable(R.drawable.bank_3);
  104.                 case 4 : return this.getResources().getDrawable(R.drawable.bank_4);
  105.                 case 7 : return this.getResources().getDrawable(R.drawable.bank_7);
  106.                 case 13 : return this.getResources().getDrawable(R.drawable.bank_13);
  107.                 case 15 : return this.getResources().getDrawable(R.drawable.bank_15);
  108.                 case 16 : return this.getResources().getDrawable(R.drawable.bank_16);
  109.                 case 17 : return this.getResources().getDrawable(R.drawable.bank_17);
  110.                 case 18 : return this.getResources().getDrawable(R.drawable.bank_18);
  111.                 case 19 : return this.getResources().getDrawable(R.drawable.bank_19);
  112.                 case 21 : return this.getResources().getDrawable(R.drawable.bank_21);
  113.                 case 24 : return this.getResources().getDrawable(R.drawable.bank_24);
  114.                 case 28 : return this.getResources().getDrawable(R.drawable.bank_28);
  115.                 case 29 : return this.getResources().getDrawable(R.drawable.bank_29);
  116.         }
  117.                
  118.         return this.getResources().getDrawable(R.drawable.map_pointer);
  119.        
  120.     }
  121.    
  122.     @Override
  123.     public boolean onKeyUp(int keyCode, KeyEvent event) {
  124.         switch(keyCode) {
  125.                 case KeyEvent.KEYCODE_BACK:
  126.                         startActivity(new Intent(this, Atm.class));
  127.             return true;
  128.         }
  129.         return false;
  130.     }
  131. }
Parsed in 0.050 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package sd.mb;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import android.app.AlertDialog;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.graphics.drawable.Drawable;
  9.  
  10. import com.google.android.maps.OverlayItem;
  11.  
  12. public class ItemizedOverlay extends com.google.android.maps.ItemizedOverlay {
  13.  
  14.         private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
  15.         private Context  mContext;
  16.  
  17.        
  18.         public ItemizedOverlay(Drawable defaultMarker, Context context) {
  19.                 //super(defaultMarker);
  20.                 super(boundCenterBottom(defaultMarker));
  21.                 mContext = context;
  22.         }
  23.  
  24.         @Override
  25.         protected OverlayItem createItem(int i) {
  26.           return mOverlays.get(i);
  27.         }
  28.  
  29.         @Override
  30.         public int size() {
  31.                 return mOverlays.size();
  32.         }
  33.        
  34.         public void addOverlay(OverlayItem overlay) {
  35.             mOverlays.add(overlay);
  36.             populate();
  37.         }
  38.        
  39.         @Override
  40.         protected boolean onTap(int index) {
  41.           OverlayItem item = mOverlays.get(index);
  42.           AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
  43.           dialog.setTitle(item.getTitle());
  44.           dialog.setMessage(item.getSnippet());
  45.           dialog.setNegativeButton( "Затвори" , new DialogInterface.OnClickListener() {
  46.                         public void onClick(DialogInterface dialog, int whichButton) {
  47.                 //Put my code in here for a negative response
  48.                         }
  49.                 });
  50.           dialog.show();
  51.           return true;
  52.         }
  53.        
  54. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
mute
Freshman
Freshman
 
Posts: 2
Joined: Sat Sep 26, 2009 1:52 pm

Top

Re: Refresh Maps

Postby JKumar » Tue Jun 01, 2010 8:59 am

HI,

The code seems to be correct but i would like to know that at which place you trying to refresh the map

And can you debug as if the back click is entering in the back call?
Hope the suggestion helps you
Keep posting .It makes us better to understand Android
User avatar
JKumar
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Thu May 13, 2010 8:17 am
Location: INDIA

Re: Refresh Maps

Postby mute » Tue Jun 01, 2010 5:26 pm

I do not try to reload the map, but it is reloaded. I see how window flashing in intervals of time,
and button back don't work, ( not back to previous activity )
mute
Freshman
Freshman
 
Posts: 2
Joined: Sat Sep 26, 2009 1:52 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 5 guests