Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Variable scope issues?

Featured Replies

Hi there, I have the following code:

 

var centerlat = 51.343225268175;
var centerlng = -4.34317803278;

	var googleMap = null;
	var previousPos = null;
	var MIN_ZOOM_LEVEL = 19;
	var MAX_ZOOM_LEVEL = 21;

	$(function($){//Called when page is loaded
		googleMap = new google.maps.Map(document.getElementById("map_canvas"), {
			zoom: MIN_ZOOM_LEVEL, 
			center: new google.maps.LatLng(centerlat, centerlng), 
			mapTypeId: google.maps.MapTypeId.ROADMAP });

var tester = [
new google.maps.LatLng(51.343225268175, -4.3430012489791 ),
new google.maps.LatLng(51.343243810758, -4.3430751462413 ),
new google.maps.LatLng(51.343018092925, -4.3431956226451 ),
new google.maps.LatLng(51.342999072325, -4.3431318564872 ),
new google.maps.LatLng(51.343225268175, -4.3430012489791 )
];

testerpoly = new google.maps.Polygon({
     paths: tester,
     strokeColor: "#FF0000",
     strokeOpacity: 0.8,
     strokeWeight: 3,
     fillColor: "#FF0000",
     fillOpacity: 0.35
/////////////////////////THIS BIT PLZ HELP!!!/////////////////////////
     freetext: "blah" 
//////////////////////////////////////////////////////////////////////
   });

   testerpoly.setMap(googleMap);
   google.maps.event.addListener(testerpoly, 'click', showArrays);

infowindow = new google.maps.InfoWindow();

function showArrays(event) {

   // Content string bit
   var contentString = "<b>Poly Clicked!</b><br />" + freetext; ///////// THIS BIT TOO!!

   // Replace our Info Window's content and position
   infowindow.setContent(contentString);
   infowindow.setPosition(event.latLng);
   infowindow.open(googleMap);
 }

});//onload
//]]>

 

For some reason the "freetext" variable is not being translated to the showArrays function... I expect that this is a fairly simple thing to resolve and would very much appreciate your help!

 

Thanks,

tozj.

Edited by tozjerimiah

Disclaimer: I'm really bad at JS.

 

Still, main problem I can see is that freetext is a property of testerpoly, have you tried this:

 

var contentString = "<b>Poly Clicked!</b><br />" + testerpoly.freetext;

  • Author

Disclaimer: I'm really bad at JS.

 

Still, main problem I can see is that freetext is a property of testerpoly, have you tried this:

 

var contentString = "<b>Poly Clicked!</b><br />" + testerpoly.freetext;

 

That works, but the issue that I have with it is that I am going to have many 'testerpoly's testerpoly1, testerpoly2, etc etc... so I would really like to have just one function that is called rather than having to make a new function per poly... thanks tho, you've shown me that there is hope!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.