On Jan 19, 10:09 pm, Marco Hoefman <[email protected]> wrote: > Hi Google Maps guru's, > > I am trying to accomplish the following: I build a map seeded with > custom markers (blue) based on what output a query from our SMC > (Smartsite) gives and I use InfoBox instead of the standard > infowindow. This all works fine. > The application has a location searchbox which whould place a > custom red marker at the given position and crops the map to the > bounds of the blue and red markers. This also works fine (I am so > proud of myself ;-). > > But here's the problem: When a user types another location I would > like the first one to be replaced by the new red marker (or > relocate it to the new location) and center the map at the new > location. How do > I do that without removing all other (blue) markers?
Keep track of the red marker separately and just remove or move it. > > Additional Q: And if I would like to crop the map to the location > and the nearmost blue marker... is there a way to do that? Yes. Find the closest blue marker (the geometry library includes distance calculations), create an empty bounds object, add the location of the red marker and the closest blue marker to it, then do map.fitBounds on that bounds. That will mean keeping track of all the blue markers (an array is good) so you can search them for the closest one. It is not good practice to geocode all your addresses everytime someone loads your page. It is quicker to load, less wasteful of Google's resources, and more extensible (that will only work for up to about 10 markers) to geocode them "off-line" (save the results from the geocode) and use the coordinates when you load the page. -- Larry > > You can find the page > here:http://imtechdev.imtechiis.nl/EN/ImtechNV/LocationsBox.html > > Please help me out :) > (And let me know if you find any other irregularities too... I'm > eager to learn more) > > TIA, > kind regards, > Marco -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
