Google Groups Home
Help | Sign in
Moving a marker along a group of points
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Blaise  
View profile
 More options Jun 27, 9:51 am
From: Blaise <JdeambuleMor...@gmail.com>
Date: Fri, 27 Jun 2008 06:51:59 -0700 (PDT)
Local: Fri, Jun 27 2008 9:51 am
Subject: Moving a marker along a group of points
Hi,

I have a group of points (latitude, longitude) and I want to move a
"marker" along these points. I am doing the following:

// I call a remote-method
public void onSuccess(Object result) {
         // LatLng is a class with latitude, longitude attributes
         LatLng[] latlng = (LatLng[])result;

         points = new GLatLng[latlng.length];

         // clear any previous overlays
         gmap.clearOverlays();

         for(int i = 0; i < points.length; i++) {
             gmap.removeOverlay(marker);

             points[i] = new
GLatLng(latlng[i].getLatitude(),

latlng[i].getLongitude());

             marker = new GMarker(points[i]);
             gmap.addOverlay(marker);

        } // end for

} // end onSuccess

I can only see the "marker" at the first position (first point). If I
move the statement "gmap.removeOverlay(marker)" after
"gmap.addOverlay(marker)", I don't see any marker which is natural.

If I don't clear the overlays or remove the marker, I see a group of
markers  each of them is located at a point. This means that I am
successfully bringing the points from the servlet. The points are
there.

Is there any suggestion on how to make 1 marker move along these
points?

Thank you,

Blaise


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andy R  
View profile
 More options Jun 27, 11:01 am
From: Andy R <andy.ros...@bluewin.ch>
Date: Fri, 27 Jun 2008 08:01:28 -0700 (PDT)
Local: Fri, Jun 27 2008 11:01 am
Subject: Re: Moving a marker along a group of points
Maybe this example can help you:
http://econym.googlepages.com/example_cartrip.htm

On 27 Jun., 15:51, Blaise <JdeambuleMor...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Williams  
View profile
 More options Jun 27, 12:30 pm
From: Mike Williams <nos...@econym.demon.co.uk>
Date: Fri, 27 Jun 2008 17:30:35 +0100
Local: Fri, Jun 27 2008 12:30 pm
Subject: Re: Moving a marker along a group of points
I'd expect this line to fail
        gmap.removeOverlay(marker);
because attempting to remove an overlay that has already been removed by
clearOverlays() should fail. Check your Javascript errors.

Once you fix things like that, you'll find that your for loop completes
before the browser display refreshes, so you'd expect only to ever see
the marker in the final position. You need to wait a while between
changes.

Adding and removing overlays is a bit inefficient. It's more efficient
to perform marker.setLatLng().

I tend to make sure that everything necessary is held in global
variables, so I can write a simple setTimeout()

var t=250;  // milliseconds

function nextframe(i) {
  marker.setLatLng(points[i]);
  i++;
  if (i<points.length) {
    setTimeout("nextframe("+i+")",t);
  }

}

marker = new GMarker(points[i]);
gmap.addOverlay(marker);
setTimeout("nextframe[0]",t);

--
http://econym.googlepages.com/index.htm
The Blackpool Community Church Javascript Team


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blaise  
View profile
 More options Jul 4, 11:25 am
From: Blaise <JdeambuleMor...@gmail.com>
Date: Fri, 4 Jul 2008 08:25:41 -0700 (PDT)
Local: Fri, Jul 4 2008 11:25 am
Subject: Re: Moving a marker along a group of points
Thanks for the help, now I understand the problem. However I am using
GWT to work with google maps. So I had to refer to the GWT Timer class
in order to wait between changes. I am still having a problem. Here is
my code:

public void onSuccess(Object result) {
                LatLng[] latlng = (LatLng[])result;

                points = new GLatLng[latlng.length];

                gmap.clearOverlays();

                for(int i = 0; i < points.length; i++) {

                        points[i] = new GLatLng(latlng[i].getLatitude(),
latlng[i].getLongitude());

                }
                marker = new GMarker(points[0]);
                gmap.addOverlay(marker);

                for(int i = 1; i < points.length; i++){
                                  nextFrame(points[i]);
                }

} // end onSuccess

private void nextFrame(final GLatLng point) {
          Timer timer = new Timer() {
                  public void run() {
                          marker.setPoint(point);
                  }
          };
          timer.schedule(250);

} // end method nextFrame

I only see the marker at the first point. The marker waits for 250
milliseconds and then directly jumps to the last point instead of
moving to the next point and so on.

Anyone can explain why is this happening? And if possible points to a
possible solution using GWT?

Thank you in advance,

--Blaise


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Ayers  
View profile
 More options Jul 4, 12:38 pm
From: "Eric Ayers" <zun...@google.com>
Date: Fri, 4 Jul 2008 12:38:02 -0400
Local: Fri, Jul 4 2008 12:38 pm
Subject: Re: Moving a marker along a group of points

Your for loop schedules all of your callbacks to go off 250seconds from the
time 'Timer.schedule()' is invoked.  In order to make them go off
sequentially, try scheduling each increment to run at Timer.schedule(250 *
(arrayIndex +1)).

I will put in my standard plug for the gwt-google-apis maps bindings that
are compatible with GWT 1.5 at http://code.google.com/p/gwt-google-apis.

Go to the download page and select 'All downloads' then 'Search' to find the
r290 release, which is the latest milestore for use with GWT 1.5.

Regards,
-Eric.

--
Eric Z. Ayers - GWT Team - Atlanta, GA USA
http://code.google.com/webtoolkit/

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blaise  
View profile
 More options Jul 7, 8:29 am
From: Blaise <JdeambuleMor...@gmail.com>
Date: Mon, 7 Jul 2008 05:29:54 -0700 (PDT)
Local: Mon, Jul 7 2008 8:29 am
Subject: Re: Moving a marker along a group of points
It works pretty well. Thanks for your help Erik

--Blaise

On Jul 4, 6:38 pm, "Eric Ayers" <zun...@google.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google