Tips for choosing markers within a polygon from a MySQL database

I am storing marker coordinates in MySQL as shown in the image linked below.

https://i.sstatic.net/taAoh.jpg

My goal is to allow users to draw on maps like the image linked below.

https://i.sstatic.net/exiAm.jpg

Then, I want to be able to retrieve the shape and select markers within that specific shape from MySQL using a query. For example:
$query = mysql_query("SELECT location FROM table WHERE Coordinates are within the polygon");


I think I may need to use AJAX and I am working with Google Maps v3. Is it possible to achieve this functionality? ANY HELP would be greatly appreciated. Any alternative ideas on how to accomplish this task?

Answer №1

When it comes to selecting coordinates inside a polygon using Google Maps, there is one limitation - Google maps does not offer GIS functions for this purpose. However, you can achieve this by leveraging the spatial extension (data type GEOMETRY) for MySQL. To learn more about how to implement this, refer to the official MySQL documentation at http://dev.mysql.com/doc/refman/5.7/en/spatial-extensions.html.

An alternative approach to select locations (points) in Google Maps involves determining the extreme values of the coordinates of the polygon points. This enables you to establish the equivalent coordinates of the rectangle that encompasses the polygon vertices. Subsequently, you can execute a SELECT query as illustrated below:

  SELECT location  
  FROM my_table 
  WHERE location_lat >= minLat_polygon
    AND location_lat <= maxLat_poligon
    AND location_lng <= maxLng_polygon
    AND location_lng >= minLng_polygon

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sorting Vue.js properties based on object keys

Currently, I am dealing with a complex object that contains multiple network interfaces. Each interface is represented by a key-value pair in the object: https://i.stack.imgur.com/klkhH.png My goal is to create a Vue.js computed property that filters thi ...

What is the best way to analyze the array?

<?php $username = "trainerapp"; $password = "password"; $hostname = "localhost"; $link = @mysql_connect($hostname, $username, $password); if (@mysql_select_db("trainer_registration")) { $select_query_num = @mysql_query("select id from program_d ...

Show the form when the button is clicked

I want to create an application that allows users to click on a button in the top right corner (check image) to hide one div (topics) and show another div (a form for adding a new topic). Here is what it looks like: https://i.stack.imgur.com/YeRTw.png ...

Issue with Ionic 2's infinite scroll not triggering method on second scroll attempt

I utilized the ion-tab element to showcase a page (inboxitem) which encompasses ion-list and makes use of ion-infinite-scroll. The following code snippet resides in inboxitem.html <ion-content class="inbox can-swipe-list"> <ion-list> ...

"Using Bootstrap's toast feature repositions every element on the

I am working on a website project and encountering an issue with a bootstrap toast. The toast currently appears in the top right corner, but I would like it to display above the carousel without affecting the layout. Instead, when the toast appears, it shi ...

Incorporate a sleek Vueitfy user interface seamlessly into your current website

Recently, I put together a sleek user interface for a web application with the help of Nuxt.js and Vuetify.js (which utilizes Vue.js code). Although my design is top-notch, I now face the challenge of integrating it into an existing website that does not ...

A step-by-step guide on extracting the image source from a targeted element

Here is a snippet of my HTML code containing multiple items: <ul class="catalog"> <li class="catalog_item catalog_item--default-view"> <div class="catalog_item_image"> <img src="/img/01.png" alt="model01" class="catalog_it ...

Passing the result of a subquery as a function parameter

I am working with two tables: Entities: | id UNSIGNED INT | pos POINT | ... | Relations: | id UNSIGNED INT | srcId UNSIGNED INT | dstId UNSIGNED INT | ... | The id columns in both tables serve as primary keys. The srcId and dstId columns of Relation act ...

How can I convert a PHP date to a JavaScript date that works across all

I am attempting to create a JavaScript countdown timer that relies on the server time, but I'm facing difficulties in transferring PHP time to JavaScript seamlessly across different browsers. While it functions correctly in modern browsers, older ones ...

Challenges with the angular timer functions .stop() and .resume()

Having trouble with my timer functionality. It seems I may have over-complicated things, but what I really need is the ability to count from 00:00 to 45:00 and pause and resume the timer within those limits. Currently, my timer code looks like this: & ...

Simple way to retrieve a value from a div without the need for any event handlers like onclick in jQuery

I am curious about how to extract values from various elements such as divs using jQuery without the need to write onclick events directly on each individual element. Here is a sample of my code: <!DOCTYPE html> <html> <head> <scri ...

When executing the mysql_query() function, I encountered an error although it was functioning properly when directly using php

When I run the following query through phpmyadmin, I get results: SET @rownr=0; SELECT TVGD.video_id,TVM.Video_Title,@rownr:=@rownr+1 AS `Order`,'0' As Min_Pass_Mark FROM tbl_video_group_details TVGD,tbl_Video_Master TVM WHERE TVGD.video_id=TVM. ...

Unlocking the Power of Rendering DOM Elements with Protractor

Recently, I began learning protractor and encountered some difficulties extracting text from a DOM object. Here is a snippet of code from an AngularJS application: "<div class="input-group application-item-field"> <input type="te ...

After being awaited recursively, the resolved promise does not perform any actions

When working with the Twitter API, I need to make recursive method calls to retrieve tweets since each request only returns a maximum of 100 tweets. The process is straightforward: Call the function and await it Make an HTTP request and await that If the ...

Is it possible to trigger an AJAX validation only after the jQuery validation plugin has successfully validated the input?

I utilized the jQuery validation plugin for form field validation. The goal now is to send an ajax request only when the fields are deemed valid by the jQuery validation plugin. JavaScript: $(function(){ $("#form").validate({ errorPlacement: ...

When attempting to save a model instance in Django that includes `auto_now_add`, an error message may be generated stating "Column 'xxx' cannot be null."

I'm feeling lost with this error that keeps popping up. Let's take a look at the Location object I have: class Location(models.Model): class Meta: db_table = 'location' location_id = models.UUIDField(primary_key=True, ...

Troubleshooting Appium error management is ineffective

As a newcomer to appium, I might have made some mistakes. I'm encountering a problem with appium while using wdio and jasmine. it('wtf', (done) => { client.init().element('someName').getText() // ^ here ...

What is the process for eliminating specific characters from a string in MySQL?

| city | | ---------------- | | Chicago (IL IN) | | New (NY) York | | (ARZ) Phoenix | Is there a method to eliminate the codes such as (IL IN), (NY), and (ARZ) from the city names? I have attempted the following code, however, it did n ...

Problems with script-driven dynamic player loading

I am attempting to load a dynamic player based on the browser being used, such as an ActiveX plugin for Internet Explorer using the object tag and VLC plugin for Firefox and Google Chrome using the embed tag. In order to achieve this, I have included a scr ...

Exploring the interplay between jQuery functions and the "Class" method in Javascript

Is there a way to reference a parent "class" method in Javascript from a jQuery function? Here's an example scenario: $Object.prototype.TestFunction = function(arg){ alert(arg); } $Object.prototype.foo = function(){ $(something).click(function ...