Jump to content

Polygon delivery area url linking


rplohocky

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";
}
});
});

 

Link to comment
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?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...