Page 1 of 1

multiple location points from a REST + info window

Posted: Mon Jun 17, 2013 10:49 am
by ciccio

how can add an info window to each of the multiple markers i loaded on my google map?

As suggested me I run the following code on the REST service success event :

Code: Select all

  var response = JSON.stringify(data); 

 localStorage.setItem("list_coordinate", response); 

 var list_coordinate = localStorage.getItem('list_coordinate'); 
 var obj = JSON.parse(list_coordinate); 
 var coordsArray = obj.coordinate; 
 var marker; 

 for (var i = 0, j = coordsArray.length; i < j; i++) { 
  marker = new google.maps.Marker({ 
   position: new google.maps.LatLng( coordsArray[i].latitudine, coordsArray[i].longitudine ), 
   title: coordsArray[i].descr, 
    map: Appery("googlemap_2").gmap 
     }); 
 }

and it works.
but i would like to open an info window on each marker click. and when the window has been opened to allow users to click on some part of the window, save a local storage variable and navigate to another page of may application.

I tested the following code just to open a info window following in some way gmap api but it doesn't work

Code: Select all

var response = JSON.stringify(data); 

 localStorage.setItem("list_coordinate", response); 

 var list_coordinate = localStorage.getItem('list_coordinate'); 
 var obj = JSON.parse(list_coordinate); 
 var coordsArray = obj.coordinate; 
 var marker; 
 var contentString = ''+ 
     ''+ 
     ''+ 
     'Uluru'+ 
     ''+ 
     ' [b]Uluru[/b], also referred to as [b]Ayers Rock[/b], is a large ' + 
     'sandstone rock formation in the southern part of the '+ 
     'Northern Territory, central Australia. It lies 335 km (208 mi) '+ 
     'south west of the nearest large town, Alice Springs; 450 km '+ 
     '(280 mi) by road. Kata Tjuta and Uluru are the two major '+ 
     'features of the Uluru - Kata Tjuta National Park. Uluru is '+ 
     'sacred to the Pitjantjatjara and Yankunytjatjara, the '+ 
     'Aboriginal people of the area. It has many springs, waterholes, '+ 
     'rock caves and ancient paintings. Uluru is listed as a World '+ 
     'Heritage Site.

 '+ 
     ' Attribution: Uluru, [url=http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194]'+ 
     'http://en.wikipedia.org/w/index.php?title=Uluru[/url] (last visited June 22, 2009).

 '+ 
     ''+ 
     ''; 

 var infowindow = new google.maps.InfoWindow({ 
     content: contentString 
 }); 
 for (var i = 0, j = coordsArray.length; i < j; i++) { 
  marker = new google.maps.Marker({ 
   position: new google.maps.LatLng( coordsArray[i].latitudine, coordsArray[i].longitudine ), 
   title: coordsArray[i].descr, 
    map: Appery("googlemap_2").gmap 
     }); 
 google.maps.event.addListener(marker, 'click', function() { 
   infowindow.open(Appery("googlemap_2"),marker); 
 }); 
 } 

multiple location points from a REST + info window

Posted: Mon Jun 17, 2013 12:30 pm
by Maryna Brodina

Hi, please use < code < /code tag to post entire code.


multiple location points from a REST + info window

Posted: Mon Jun 17, 2013 1:22 pm
by ciccio

sorry,
the code that i run on service success event is
code
var coordsArray = data&#46;coordinate;
var marker;

for (var i = 0, j = coordsArray&#46;length; i < j; i++) {
marker = new google&#46;maps&#46;Marker({
position: new google&#46;maps&#46;LatLng( coordsArray&#46;latitudine, coordsArray&#46;longitudine ),
title: coordsArray&#46;descr,
map: Appery("googlemap_2")&#46;gmap
});
}/code

and the code i tested but is not working is:
code
var coordsArray = data&#46;coordinate;
var marker;
var contentString ="hello&quot

var infowindow = new google&#46;maps&#46;InfoWindow({
content: contentString
});
for (var i = 0, j = coordsArray&#46;length; i < j; i++) {
marker = new google&#46;maps&#46;Marker({
position: new google&#46;maps&#46;LatLng( coordsArray&#46;latitudine, coordsArray&#46;longitudine ),
title: coordsArray&#46;descr,
map: Appery("googlemap_2")&#46;gmap
});
google&#46;maps&#46;event&#46;addListener(marker, 'click', function() {
infowindow&#46;open(Appery("googlemap_2"),marker);
});
} /code


multiple location points from a REST + info window

Posted: Mon Jun 17, 2013 2:45 pm
by ciccio

i solved the problem by using the second code proposed by changing codeAppery("googlemap_2")&#46;gmap/code
with
codeinfowindow.open(Appery("googlemap_2")&#46;gmap ,marker); /code


multiple location points from a REST + info window

Posted: Mon Jun 17, 2013 3:26 pm
by Marco Della Gala

Actually i changed the code infowindow.open(Appery("googlemap_2"),marker)