Check if an address is within an area map

三世轮回 提交于 2019-12-07 13:44:48

问题


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.


回答1:


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/



来源:https://stackoverflow.com/questions/39607189/check-if-an-address-is-within-an-area-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!