javascript - Google Maps JS API v3 - Simple Multiple Marker Example -
is an array of fairly new I have data in Google Maps API do what I want to cycle and plot a cycle. Looks quite simple, but I've found that all the Multi Marker tutorials are quite complex.
For example, use the data array of Google's site:
var locations = [ 'Bondi Beach', -33.890542, 151.274856, 4], [ 'Kogi Meanwhile, -33.923036, 151.25 9 52, 5], [ 'Cronulla beach, -34.02824 9, 151.157507, 3], [' Manly beach ', - 33.80010128657071, 151.28747820854187, 2], [' Maroubra beach ', -33.950198 , 151.259302, 1]]; I just want to plot all these points and I name should get an info window that pops up when you click to display.
Any help is greatly appreciated!
This is the simplest, I can reduce it have:
& Lt ;! DOCTYPE html & gt; ; & Lt; Html & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Google Maps offers many markers & lt; / Title & gt; & Lt; script src = "http://maps.google.com/maps/api/js?sensor=false" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; div id = "map" style = "width: 500px; height: 400px;" & Gt; & Lt; / Div & gt; & Lt; Script type = "text / javascript" & gt; Var Location = [['Bondi Beach', -33.890542, 151.274856, 4], ['Kogi Beach', -33.923036, 151.25 9 52, 5], ['Cronulla Beach', -34.02824 9, 151.157507, 3], [ 'Manly Beach', -33.80010128657071, 151.28747820854187, 2], ['Maroubra Beach', -33.950198, 151.259302, 1]]; Var map = new google.maps.Map (document.getElementById ('map'), {zoom: 10, center: new google.maps.LatLng (-33.92, 151.25), type the map: google.maps.MapTypeId.ROADMAP }); Var infowindow = new google.maps.InfoWindow (); 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}); Google.maps.event.addListener (Marker, 'click', (function (marker, i) {return function () {infowindow.setContent (places [i] [0]); infowindow.open (map, marker);} }) (Marker, I)); } & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt; Screenshots:
There is some closing magic when the callback argument is going through the addListener method, it can be a very difficult topic, if you are not familiar, how the closures work. I suggest checking for the following Mozilla article for a brief introduction, if this is the case: -
Comments
Post a Comment