?
Solved

Help in debugging Javascript issue

Posted on 2012-04-11
10
Medium Priority
?
249 Views
Last Modified: 2012-04-15
I have a google map that is rendering via a Javascript

Old working script: http://sandbox5.project4.net/landing/v1.asp

I sought some advice on simplifying the code - however the suggestion I got does not render.  This new suggested broken script is here;

New broken script: http://sandbox5.project4.net/landing/v2.asp

There is some problem with the Javascript but I am unable to determine what.

Does anybody have an idea what the problem may be?
0
Comment
Question by:sonic1234
  • 5
  • 3
9 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37836092
change the equals signs to colons here

regionNOROC =

and

regionMIDGOC =
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37836096
so you end up with

 regionNOROC:

and

 regionMIDGOC:
0
 

Author Comment

by:sonic1234
ID: 37840897
Thanks, have tried your suggestion;

http://sandbox5.project4.net/landing/v3.asp

Still does not render unfortunately
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37847787
Load into firefox and look in the console

Timestamp: 15/04/2012 08:50:12
Error: missing : after property id
Source File: v3.asp
Line: 18, Column: 14
Source Code:
      latlngs = [
0
 
LVL 23

Accepted Solution

by:
basicinstinct earned 2000 total points
ID: 37848078
here is your code, fixed:
var map;
  var infoWindow;
  var regions = {
    regionNOROC: {
      regitonTitle: "Region title for region NOROC",
      latlngs: [
        {lat:-28.25,lng:153.54},
        {lat:-28.47,lng:154.13},
        {lat:-29.9,lng:153.70},
        {lat:-29.96,lng:151.78},
        {lat:-28.43,lng:152.37}
      ]
    },
    regionMIDGOC: {
      regitonTitle: "Region title for region MIDGOC",
      latlngs: [
        {lat:-29.96,lng:151.78},
        {lat:-29.9,lng:153.70},
        {lat:-32.68,lng:152.95},
        {lat:-32.28,lng:149.61},
        {lat:-30.19,lng:150.20}
      ]
    }
  }; // note the lack of commas after last items
  function initialize() {
    var myLatLng = new google.maps.LatLng(-30.62, 148.8);
    var myOptions = {
      zoom: 7,
      center: myLatLng,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    };

    map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);


  // Start Regions ----------------- 

    for (var region in regions) {
    
      var paths = [];
      var pathArr = regions[region].latlngs; 
      for (var i = 0;i<pathArr.length;i++) {
        paths[i] = new google.maps.LatLng(pathArr[i].lat,pathArr[i].lat); 
      }

      var googleRegion = new google.maps.Polygon({
        paths: paths,
        strokeColor: "#FF0000",
        strokeOpacity: 0.8,
        strokeWeight: 3,
        fillColor: "#FF0000",
        fillOpacity: 0.35
      }); 

      googleRegion.setMap(map);

      // Add a listener for the click event
      google.maps.event.addListener(googleRegion, 'click',
        function() {
          // Since this Polygon only has one path, we can call getPath()
          // to return the MVCArray of LatLngs
          var vertices = this.getPath();
          var contentString = regions[region].regitonTitle;
          // Replace our Info Window's content and position
          infowindow.setContent(contentString);
          infowindow.setPosition(event.latLng);
          infowindow.open(map);
       });


  // End Regions ----------------- 
    
    infowindow = new google.maps.InfoWindow();
  }
}

Open in new window

0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37848082
in short:

- missing curly brace at end of script block
- using equals signs instead of colons to define the following object literal properties:

-- regionNOROC
-- latlngs
-- regionMIDGOC
-- latlngs
0
 

Author Closing Comment

by:sonic1234
ID: 37848090
Greatly appreciated
0
 

Author Comment

by:sonic1234
ID: 37848298
Sorry noticed the polygons don't render on the map still

See;

http://sandbox5.project4.net/landing/v4.asp

As compared to with polygons;

See http://sandbox5.project4.net/landing/v1.asp
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37849107
well it's your code right, so point us in the right direction...

Which part of your code is failing? i.e. where do those polygons come from? which part of your code draws them or asks them to be drawn?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question