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.
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
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.
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.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With