Sunday, 15 July 2012

javascript - set Google Map zoom automatically from result set -


I am using Google Maps with my CMS search tool and I have a collection of stores successfully in a list and Google Maps based on a search may not seem to work for me, although setting up the zoom automatically for the map and fitting in all the returning markers on the map. I have seen many other posts about this type but all maps are related to the API's v2 What do I have to set this to zoom and fit

  var iconBase = '/ img /'; Var icons = {Parent: {icon: iconBase + 'parent.png}}, Children: {icon: iconBase +' child.png '}} var locations = [{exp: low_search: results query = "{segment_3}" backspace = "1"} ["{title}", {latitude}, {underline}, "{type}", "& lt; p> {street_address}" & lt; Br> {City} & lt; Br> {ZIP} & lt; / P & gt; "," {Website} "], {/ exp: low_search: results}] var map = new google.maps.Map (document.getElementById ('map'), {mapTypeId: google.maps.MapTypeId.ROADMAP}) ; Var infowindow = New google.maps.InfoWindow (); Var MarkerBound = New google.maps.LatLngBounds (Var); Var Marker, i; (I = 0; i & lt; locations.length; i ++) {Marker = New google.maps.marker ({status: new google.maps.LatLng (places [i] [1], location [i] [2]), map: map, icon: location [i] [3] == " Yes'? '/img/parent.png': '/img/child.png', address: location [i] [4]}); markerBounds.extend (marker); Google.maps.event.addListener (marker, 'Click', (function (marker, i) {return function () {infowindow.setContent ('& lt; h2 & gt;' + s [I] [0] + '& lt; / h2 & gt;' + this.address + '& lt; p & gt; & lt; a href = "' + location [i] [5] + ' "& Gt; Website & lt; / a & gt; '); infowindow.open (map, marker);};}) (marker, i));} map.fitBounds (markback);  

I'm unsuccessful here?

To clarify, when I remove markbank and fitbounds, then when I see a work map. It seems that the error is occurring on the console markerBounds.extend (marker);

Easy to remember you markerBounds.extend () A marker is giving objects, but in fact it requires a google.maps.LatLng object. Try it out:

  var marker, i, marker lotleng; (I = 0; i & lt; locations.length; i ++) {if (location [i] .length & gt; {) markerLatLng = new google.maps.LatLng (places [i] [1], location [I] [2]); } Else {markerLatLng = new google.maps.LatLng (37.778190, -122.420434); } Marker = New google.maps.Marker ({location: markerLatLng, map: map, icon: places [i] [3] == "yes"? '/img/parent.png': '/img/child.png ', Address: places [ii] [4]}); MarkerBounds.extend (markerLatLng); Google.maps.event.addListener (marker, 'click', (function (marker, i) {return function () {infowindow.setContent ('& lt; h2 & gt;' + locations [i] [0] + ' & Lt; / h2 & gt; '+ this.address +' & lt; p & gt; & lt; a href = "'+ location [i] [5] +'" & gt; website & lt; / A & gt; '); infowindow.open (map, marker);};}) (marker, i)); } Map.fitBounds (markback); I have declared a new variable that is assigned to a  google.maps.LatLng  object within the loop, which then returns to  Markerbond. Extension ()  method 


No comments:

Post a Comment