Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Help in debugging Javascript issue

Posted on 2012-04-11
10
243 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
10 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get Pixel color of the x and y axis Html without canvas 8 50
Index on a Table 6 25
Underline in nav for the page that you are currently on. 1 22
html border input line 7 13
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

807 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