Jump to content
Sign in to follow this  
rplohocky

Polygon delivery area url linking

Recommended Posts

Hello,
This is my first post on this site!

I use a wordpress site and am using a plugin that works with Google maps. I wrote some code and it doesn’t seem to be working. The plugin works with service areas that you make on the map. When a customer searches for there address the code is supposed to check if it falls inside a polygon or not and then take them to one page or another. I have 5 polygons and this code is programmed to send customers to different pages based on where there address appears. Can someone look at the code to see what I’m missing?

jQuery(function($) {
$('body').on('storelocatorresult.wpgmza', function(event) {

var location = new google.maps.LatLng(event.center);

//you can add multiple polygon IDs by separating with a comma
var contains = google.maps.geometry.poly.containsLocation(location, WPGM_Path_Polygon[1]);

if (!contains) {
// outside of polygon
window.location.href = "outofarea";
} else {
// inside polygon
window.location.href = "fiber";
}
});
});

jQuery(function($) {
$('body').on('storelocatorresult.wpgmza', function(event) {

var location = new google.maps.LatLng(event.center);

//you can add multiple polygon IDs by separating with a comma
var contains = google.maps.geometry.poly.containsLocation(location, WPGM_Path_Polygon[2]);

if (!contains) {
// outside of polygon
window.location.href = "outofarea";
} else {
// inside polygon
window.location.href = "fiber";
}
});
});

jQuery(function($) {
$('body').on('storelocatorresult.wpgmza', function(event) {

var location = new google.maps.LatLng(event.center);

//you can add multiple polygon IDs by separating with a comma
var contains = google.maps.geometry.poly.containsLocation(location, WPGM_Path_Polygon[3]);

if (!contains) {
// outside of polygon
window.location.href = "outofarea";
} else {
// inside polygon
window.location.href = "fixedwireless";
}
});
});

jQuery(function($) {
$('body').on('storelocatorresult.wpgmza', function(event) {

var location = new google.maps.LatLng(event.center);

//you can add multiple polygon IDs by separating with a comma
var contains = google.maps.geometry.poly.containsLocation(location, WPGM_Path_Polygon[4]);

if (!contains) {
// outside of polygon
window.location.href = "outofarea";
} else {
// inside polygon
window.location.href = "comingsoon";
}
});
});

jQuery(function($) {
$('body').on('storelocatorresult.wpgmza', function(event) {

var location = new google.maps.LatLng(event.center);

//you can add multiple polygon IDs by separating with a comma
var contains = google.maps.geometry.poly.containsLocation(location, WPGM_Path_Polygon[5]);

if (!contains) {
// outside of polygon
window.location.href = "outofarea";
} else {
// inside polygon
window.location.href = "ltewireless";
}
});
});

 

Share this post


Link to post
Share on other sites

Hi there, welcome to the Forums!

When you use a code block, you may want to select the language that you're writing in so that the syntax highlighting is correct for it.

You also might have a bit of an easier time following your program flow if you include indentation.

 

 

What are you expecting to happen, vs what's actually happening here?

 

Is nothing happening?

Do you always end up in "outofarea"?

 

Is there a design choice surrounding the use of multiple event handlers for the different polygons?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...