Drawing many points on Map

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

Drawing many points on Map

Postby Kamal » Mon Jun 01, 2009 3:39 pm

Hi All,

I have an application where i have to draw many points on the map and finally have to join them.

The points will be increasing.......almost like a path.

I am trying to use draw method of overlay class. something like....

class MapOverlay extends Overlay
{
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
//draw points and join them
}
}


Since the points are growing, i have to redraw all the points and join them everytime.

Is this the right way of doing ?

Is there any way by which i can avoid plotting of already drawn points and just put a new point on the map ?

Helps are highly appreciated......
Kamal
Junior Developer
Junior Developer
 
Posts: 23
Joined: Wed May 27, 2009 11:15 am

Top

Postby iifuzz » Wed Jun 03, 2009 7:26 pm

Hope this helps.



Initialized globally...
HelloItemizedOverlay ControlPoints;
Drawable drawable;
List<Overlay> mapOverlays;
OverlayItem overlayitem;


Called OnCreate...
drawable = this.getResources().getDrawable(R.drawable.bluedot);
ControlPoints = new HelloItemizedOverlay(drawable);


Called When adding points...

GeoPoint point2 = new GeoPoint(Integer.parseInt(ParsedString[1]),Integer.parseInt(ParsedString[0]));
overlayitem = new OverlayItem(point2, "", "");
ControlPoints.addOverlay(overlayitem);

Called after adding all points to ControlPoints in order to display them...
if(ToggleControl == true && ControlPoints.size() > 0)
mapOverlays.add(ControlPoints);


HelloItemizedOverlay.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.example.helloandroid2;
  3.  
  4. import java.util.ArrayList;
  5.  
  6. import android.graphics.drawable.Drawable;
  7.  
  8. import com.google.android.maps.ItemizedOverlay;
  9. import com.google.android.maps.OverlayItem;
  10.  
  11. @SuppressWarnings("unchecked")
  12. public class HelloItemizedOverlay extends ItemizedOverlay {
  13.         private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
  14.        
  15.         public HelloItemizedOverlay(Drawable defaultMarker) {
  16.                 super(boundCenter(defaultMarker));
  17.  
  18.         }
  19.  
  20.         @Override
  21.         protected OverlayItem createItem(int i) {
  22.  
  23.                 return mOverlays.get(i);
  24.         }
  25.  
  26.         @Override
  27.         public int size() {
  28.  
  29.                 return mOverlays.size();
  30.         }
  31.        
  32.         public void addOverlay(OverlayItem overlay) {
  33.             mOverlays.add(overlay);
  34.             populate();
  35.         }
  36.        
  37.         public void ClearOverlay() {
  38.             mOverlays.clear();
  39.         }
  40.                
  41. }
  42.  
  43.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
iifuzz
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu May 21, 2009 6:00 pm

Drawing many points on Map

Postby Kamal » Thu Jun 04, 2009 11:33 am

Hi iifuzz....

Thanks for the reply....

As you mentioned i have added these codes as global:
HelloItemizedOverlay ControlPoints;
Drawable drawable;
List<Overlay> mapOverlays;
OverlayItem overlayitem;

I have added this at onCreate
drawable = this.getResources().getDrawable(R.drawable.dot);
ControlPoints = new HelloItemizedOverlay(drawable);

I have two editTexts and a button. I enter Lat and lon on the editboxes and button.
for the button listener, I have added these codes:
overlayitem = new OverlayItem(Point[0], "", "");
ControlPoints.addOverlay(overlayitem);

Just after this I have added:
if(ControlPoints.size() > 0)
mapOverlays.add(ControlPoints);

Now the problem is i get exception at mapOverlays.add(ControlPoints);

How the points are drawn... Just by calling mapOverlays.add(ControlPoints); will the points be drawn..? Do I have to do anything at draw method...?
Kamal
Junior Developer
Junior Developer
 
Posts: 23
Joined: Wed May 27, 2009 11:15 am

Postby iifuzz » Thu Jun 04, 2009 12:12 pm

no, you do not need to do anything in the draw method.

the mapview draws them automatically as if they were placemarks in google earth.


whats the error say?
iifuzz
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu May 21, 2009 6:00 pm

Error Details

Postby Kamal » Thu Jun 04, 2009 1:38 pm

Hi iifuzz....

This is the error log:

06-04 18:06:35.211: DEBUG/AndroidRuntime(499): Shutting down VM
06-04 18:06:35.211: WARN/dalvikvm(499): threadid=3: thread exiting with uncaught exception (group=0x40010e28)
06-04 18:06:35.211: ERROR/AndroidRuntime(499): Uncaught handler: thread main exiting due to uncaught exception
06-04 18:06:35.339: ERROR/AndroidRuntime(499): java.lang.NullPointerException
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at bst.google.maps.MapsActivity$1.onClick(MapsActivity.java:796)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.view.View.performClick(View.java:2109)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.view.View.onTouchEvent(View.java:3523)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.widget.TextView.onTouchEvent(TextView.java:4410)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.view.View.dispatchTouchEvent(View.java:3178)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1561)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1085)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.app.Activity.dispatchTouchEvent(Activity.java:1873)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1545)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.view.ViewRoot.handleMessage(ViewRoot.java:1140)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.os.Handler.dispatchMessage(Handler.java:88)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.os.Looper.loop(Looper.java:123)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at android.app.ActivityThread.main(ActivityThread.java:3742)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at java.lang.reflect.Method.invoke(Method.java:515)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
06-04 18:06:35.339: ERROR/AndroidRuntime(499): at dalvik.system.NativeStart.main(Native Method)
06-04 18:06:35.429: INFO/Process(47): Sending signal. PID: 499 SIG: 3
06-04 18:06:35.489: INFO/dalvikvm(499): threadid=7: reacting to signal 3
06-04 18:06:35.539: INFO/dalvikvm(499): Wrote stack trace to '/data/anr/traces.txt'
Kamal
Junior Developer
Junior Developer
 
Posts: 23
Joined: Wed May 27, 2009 11:15 am

Postby iifuzz » Thu Jun 04, 2009 2:02 pm

Try adding this in the OnCreate.. i left it out in the first post.

mapView = (MapView) findViewById(R.id.mapview);
mapOverlays = mapView.getOverlays();



Globally
MapView mapView;
List<Overlay> mapOverlays;



if that doesnt work. i dont know, its working for me :(
iifuzz
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu May 21, 2009 6:00 pm

Top

It works

Postby Kamal » Thu Jun 04, 2009 2:05 pm

Hi iifuzz....

Its greate... it works....

Now one more thing... I need to connect these points.....

Also i need to rotate the map....

Any help will be highly appreciated....
Kamal
Junior Developer
Junior Developer
 
Posts: 23
Joined: Wed May 27, 2009 11:15 am

Postby iifuzz » Thu Jun 04, 2009 2:11 pm

im not that far yet either ^_^
iifuzz
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu May 21, 2009 6:00 pm

Postby Kamal » Thu Jun 04, 2009 2:30 pm

Any other way to join the points....?

May be a different approch....?
Kamal
Junior Developer
Junior Developer
 
Posts: 23
Joined: Wed May 27, 2009 11:15 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests