Gmap3 - Forum

Gmap3 exchange platform

You are not logged in.

Ads
(server costs 27.50€ per month)

#1 2012-06-20 18:36:46

bambou
Member
Registered: 2012-06-20
Posts: 2

Markers from external data (JSON)

hello,
I have a problem of displaying markers to retrieve data from an external file. M Console returns this error and I do not know what I'm doing wrong:

error: invalid 'in' operand todo[property][i...

My data: (data.json)

{ "latitude":49.17698, "longitude":16.404793, "title":"Angered", "content":"Representing :)" },
{ "latitude":57.6969943, "longitude":11.9865, "title":"Gothenburg", "content":"Swedens second largest city" }

My script:

 
	$.post('http://localhost/data/data.json', function(data) {

		$("#main-map").gmap3(
		{ action:'init',
		options:{
		center:[49.196961,16.612644],
		zoom: 7,
		}
		},
		
		{ action: 'addMarkers',markers: data,
	marker:{
		options:{
			draggable: false
		},
	events:{
		click: function(marker, event, data){
			var map = $(this).gmap3('get'),
				infowindow = $(this).gmap3({action:'get', name:'infowindow'});
					if (infowindow){
						infowindow.close();
						infowindow.open(map, marker);
						infowindow.setContent(data);
							
					} else {
						$(this).gmap3({action:'addinfowindow', anchor:marker, options:{content: data}});
					}
		}
	}
}
}
	);
	});
	}

you advise me, or is somewhere functional demonstration of retrieving data from an external file (txt, JSON).

thank you

Tomas

Offline

Ads
(server costs 27.50€ per month)

#2 2012-06-20 19:20:33

charlietfl
Moderator
Registered: 2011-11-24
Posts: 201

Re: Markers from external data (JSON)

working simple json ajax markers demo
http://jsfiddle.net/charlietfl/S8kd3/

try changing "content" in your json object to "data"

Offline

#3 2012-06-20 19:51:37

bambou
Member
Registered: 2012-06-20
Posts: 2

Re: Markers from external data (JSON)

Thanks,
I tried to change the UTR to load data in your example, but does not appear to me, a map but there is no error. We really do not know.

source data http://www.bambou.cz/data/data.json.htm

the problem is the data?

Offline

#4 2012-06-21 10:52:59

jbdemonte
Administrator
From: Pourrières, France
Registered: 2011-11-21
Posts: 477

Re: Markers from external data (JSON)

replace latitude by lat and logitude by lng (and no need the quote in property name):

{ lat:49.17698, lng:16.404793, ... },
{ lat:57.6969943, lng:11.9865, ... }

Offline

Board footer

Powered by FluxBB