Hey there, Anyone able to give me a pointer on this one? I have a Gmap (v3) with multiple points plotted on it as markers. One marker is the persons location that they searched for, the others are the stores in the area... The Map always shows the 5 (max) nearest stores within 25 miles of the search point. Is there a function within mapstraction to set the zoom level programatically to always show the markers, but be centred on the start point? Help appreciated! Steve -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20101021/945c0987/attachment.htm>
I don''t think this will do it perfectly but we do something similar 1. determine the bounding box of the stores and the user - loop through and get max and min lat and lng 2. set the mxn object to have those bounds mxn.setBounds( new mxn.BoundingBox( sw_lat, sw_lng, ne_lat, ne_lng ) ); 3. get the zoom that encloses those points var zoom_level = mxn.getZoom(); 4. centre on the user, at that zoom mxn.setCenterAndZoom( new mxn.LatLonPoint( c_lat, c_lng ), zoom_level ); 2010/10/21 Steve Kirtley <steve.kirtley at gmail.com>:> Hey there, > Anyone able to give me a pointer on this one? > I have a Gmap (v3) with multiple points plotted on it as markers. > One marker is the persons location that they searched for, the others are > the stores in the area... > The Map always shows the 5 (max) nearest stores within 25 miles of the > search point. > Is there a function within mapstraction to set the zoom level > programatically to always show the markers, but be centred on the start > point? > Help appreciated! > Steve > _______________________________________________ > Mapstraction mailing list > Mapstraction at lists.mapstraction.com > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com > >
Hi, Le 21/10/2010 17:53, Steve Kirtley a ?crit :> Is there a function within mapstraction to set the zoom level > programatically to always show the markers, but be centred on the start > point? >Not sure but this one should do the job : autoCenterAndZoom() autoCenterAndZoom sets the center and zoom of the map to the smallest bounding box containing all markers ++ b_b
Thanks Bruno, It sounds like the ideal function, but when using it it seems to go to minimum zoom and show the whole world with all my markers on top of eachother.... Is this a bug does anyone know? Steve On Thu, Oct 21, 2010 at 5:44 PM, Bruno Bergot <brunobergot at gmail.com> wrote:> Hi, > > Le 21/10/2010 17:53, Steve Kirtley a ?crit : > > > Is there a function within mapstraction to set the zoom level >> programatically to always show the markers, but be centred on the start >> point? >> >> > Not sure but this one should do the job : > > > autoCenterAndZoom() > > autoCenterAndZoom sets the center and zoom of the map to the smallest > bounding box containing all markers > > ++ > b_b > > _______________________________________________ > Mapstraction mailing list > Mapstraction at lists.mapstraction.com > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20101021/6b4235eb/attachment.htm>
Thanks Ed, Will try this now :) Steve On Thu, Oct 21, 2010 at 5:03 PM, Ed Freyfogle <edf at sloan.mit.edu> wrote:> I don''t think this will do it perfectly but we do something similar > > > 1. determine the bounding box of the stores and the user > - loop through and get max and min lat and lng > > 2. set the mxn object to have those bounds > mxn.setBounds( > new mxn.BoundingBox( sw_lat, sw_lng, ne_lat, ne_lng ) > ); > > 3. get the zoom that encloses those points > var zoom_level = mxn.getZoom(); > > 4. centre on the user, at that zoom > mxn.setCenterAndZoom( > new mxn.LatLonPoint( c_lat, c_lng ), > zoom_level > ); > > > > > > > > > 2010/10/21 Steve Kirtley <steve.kirtley at gmail.com>: > > Hey there, > > Anyone able to give me a pointer on this one? > > I have a Gmap (v3) with multiple points plotted on it as markers. > > One marker is the persons location that they searched for, the others are > > the stores in the area... > > The Map always shows the 5 (max) nearest stores within 25 miles of the > > search point. > > Is there a function within mapstraction to set the zoom level > > programatically to always show the markers, but be centred on the start > > point? > > Help appreciated! > > Steve > > _______________________________________________ > > Mapstraction mailing list > > Mapstraction at lists.mapstraction.com > > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com > > > > > _______________________________________________ > Mapstraction mailing list > Mapstraction at lists.mapstraction.com > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20101021/8d1835b7/attachment.htm>
Hi Steve, I''ve just tested mapstraction.autoCenterAndZoom(); on a map containing many markers and it works as expected... ++ b_b Le 21/10/2010 18:54, Steve Kirtley a ?crit :> Thanks Bruno, > > It sounds like the ideal function, but when using it it seems to go to > minimum zoom and show the whole world with all my markers on top of > eachother.... > Is this a bug does anyone know? > > Steve
autoCenterAndZoom centers on the median point of all the markers on the map and sets the zoom level so that they''re all visible. You want to be centered on a particular point whilst setting your zoom so that the other markers on the map are all visible. You need to do something similar to what Ed suggested to achieve this. 1. Find the bounding box of all the markers including your center point 2. Rotate that 180 degrees around your center point to give you another bounding box 3. Add this new bounding box to the original using BoundingBox.extend() 4. Call Mapstraction.getZoomLevelForBoundingBox() with the resultant box to get your zoom level 5. Call Mapstraction.setCenterAndZoom passing your center point and calculated zoom level Derek On 23 October 2010 15:56, Bruno Bergot <brunobergot at gmail.com> wrote:> Hi Steve, > > I''ve just tested mapstraction.autoCenterAndZoom(); on a map containing many > markers and it works as expected... > > ++ > b_b > > Le 21/10/2010 18:54, Steve Kirtley a ?crit : > > Thanks Bruno, >> >> It sounds like the ideal function, but when using it it seems to go to >> minimum zoom and show the whole world with all my markers on top of >> eachother.... >> Is this a bug does anyone know? >> >> Steve >> > > _______________________________________________ > Mapstraction mailing list > Mapstraction at lists.mapstraction.com > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >-- Derek Fowler m. +44 (0) 7966 512 369 e. dezfowler at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20101024/d1745b32/attachment.htm>