Hi,

It sounds like you're reading Gabriel Svennerberg's book. I can't
speak to using the output from the Styled Map Wizard in the way that
you describe, but as far as reading data from a JSON and using it to
populate a Google Map (API v3) an example is located here:

http://gis.zgroks.com/NYwithCountyLabels.html //

This example reads from a JSON file and creates moveable (Infobox)
labels for the counties of New York State. The take away is how to
read the JSON file.It shows one way to loop through a JSON file and
grab the properties from the file to create markers or do whatever.

In the example above, the data is stored in the file: "http://
gis.zgroks.com/nyCountyLabeldata.json". The JSON file consists of the
array "centroid[]" and starts and ends like what's below:

var centroid = [
{"countyFIPS": "001"     ,"countyName": "Albany      ","population":
304204    ,"lat": 42.678976,"lng":-73.813040 },
... Rest of the data goes here ...
{"countyFIPS": "123"     ,"countyName": "Yates       ","population":
25348     ,"lat": 42.633657,"lng":-77.078037 }
];

This data file is pulled into the main script like this:

<script type="text/javascript" src="nyCountyLabeldata.json"></
script> // right after you pull in the Google Maps Api v3 ...

This gives your script access to the JSON object as a "global
variable".

To loop through the JSON object, the script says this:

  for(var i=0; i<centroid.length; i++){
        var obj = centroid[i];
         var latLng = new google.maps.LatLng(obj.lat,obj.lng);
          var pops= obj.population;
          var labelText2 = obj.countyName + " County ";
        var marker = new google.maps.Marker({
         position: latLng, //
         });
           var myOptions = { // code omitted from example; // end
myOptions
        var ibLabel2 = new InfoBox(myOptions);
        ibLabel2.open(map,marker);
 } // end of loop that reads the JSON file

The loop traverses the centroid[] array. In turn, each element is
assigned to 'obj'. Each time through the loop you read whatever you
want from the variable obj[i] such as obj.population which is the same
as obj[i].population, etc. Before the script leaves the loop, it does
whatever it needs to do with the properties that are read from each
element of the centeroid[] array.

I'm sure there are better, more elegant/unobtrusive ways in which to
do this and you could read from an XML file as well; however this does
work as a starting point.

Regards,

Bob













On Jul 24, 12:15 pm, Carta <s...@cartagram.com> wrote:
> I'm beginning to learn how to customize Google Maps. I did some
> customization in Google's Styled Map Wizard and exported the JSON code
> and customized it more. The map is 
> athttp://www.cartagram.com/maps/madisonal/madisonal.html
>
> Question: a book I'm reading on Google Maps suggests keeping a
> seperate folder for the javascript and for the css. So I've been
> trying to convert the JSON code to a .js file and running it from a
> simplified .html file with a link to the .css and the .js.
>
> No luck.
>
> Any suggestions?

-- 
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 google-maps-js-api-v3@googlegroups.com.
To unsubscribe from this group, send email to 
google-maps-js-api-v3+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to