Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if an address is within an area map

The need I have is that a user (client) can put his/her address and to validate if it is within our delivery area.

Currently I have designed this layer on google maps:

https://www.google.com/maps/d/u/0/viewer?mid=1E3bcIm6Dy4icmTA4S-hEqOZeHpU

What is the technology that I use?

I just need an input text of a formulary to write the address and respond with an OK or a sorry.

All the information that I find are questions and solutions to calculate routes and only need to verify an address within an area.

Now I know as autofill and get save the address to verify. Now I just need to know how I can verify that direction in my area.

like image 540
Gabriel Calle Torrez Avatar asked Sep 21 '16 03:09

Gabriel Calle Torrez


People also ask

How do I check if an address is in city limits?

Quickly check if an address is in city limits and see a city borders map. See all city boundaries or city lines, and optionally show township and county boundaries. See a city limits map on Google Maps • Find city by address • Answer what city is this address in

How do I search Places on the map?

In the “Search places” box above the map, type an address, city, etc. and choose the one you want from the auto-complete list* OR: Click the map to see the city name for where you clicked or just type another place name or address OR: Click the ◉ button in the upper right corner of the map to use your current location.

How do I find a specific city on a map?

At the top of the map, the city name will appear, along with a Class code (see below for details), the area of the city in square miles, and the Latitude/Longitude for the blue dot. † * You can also type in GPS coordinates in decimal degrees into the Search places box.

How do I find the county on the map?

You can also find the county by searching an address or by clicking on the map. The county borders are displayed on the map. Searching for a city may not give you a result.


1 Answers

Here is a sketch for you: https://jsfiddle.net/zw6f78xk/

First the Place Autocomplete was used to input an address, which gives you the location of the address

Then the location is checked whether it is inside the polygon.

google.maps.geometry.poly.containsLocation(place.geometry.location, polygon)

Hope this helps.

Update:

But now because you already have the polygon on your google map, it is easy to modify its shape and retrieve its coordinates. Just add editable: true to the polygon options then you can modify it manually and finally you can get the coordinates for example like this:

google.maps.event.addListener(polygon, 'click', function(evt) { 
    var pathArray = polygon.getPath().getArray();
    for (var i = 0; i < pathArray.length; i++){
        console.log(pathArray[i].toUrlValue());
    };
});

So clicking on the polygon it logs its path.

Update 2:

Geocoding the typed (but not selected from the autocomplete) address. https://jsfiddle.net/zw6f78xk/3/

like image 154
MKiss Avatar answered Oct 06 '22 06:10

MKiss