Find users living between a specified distance (using custom zipcode)

Is there a way to find the radial distance using zipcode?

My task is to search for all users living at a specified distance. I know zipcodes of users.

For example, users are within a radius of 25 miles of their current location.

I have other search categories for which I use mysql queries. I can’t understand anything about the issue of distance.

My backend is in php and the interface is in Flex.

The best option for me is something like www.zip-codes.com/zip-code-radius-finder.asp. those. if I should be able to get all the postal codes available at the indicated radial distance. Therefore, I can compare these zip codes with the user zip codes in my database. And select those that have a match.

Please help me with this. Zeeshan

+3
source share
5 answers

I did something similar using the free Google Maps API, which may be good enough for use and for your needs.

http://googlemapsapi.blogspot.com/2006/06/geocoding-at-last.html - short message on this issue (since 2006)

http://code.google.com/apis/maps/index.html - Google Maps API home

+8

. lat/long, lat/long. , ​​ -, / .

+6

  • ( )
  • sql zip (, ZIP_DIST (zip1, zip2))
  • , .
  • , N .

, MySQL. API .

+2

Of course, you can implement some code from the Google APIs, but here is a small project that I wrote for you, and its view looks below: btw i got one of services from google output like free-zipcode-maps.com/tools/zipcoderadius/extractzips2.cgi?Zip_Code=90503&Miles=30

here is the code:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <s:layout>
        <s:VerticalLayout/>
    </s:layout>

    <fx:Declarations>
        <s:HTTPService id="service" resultFormat="text" result="service_resultHandler(event)" fault="Alert.show(event.fault.toString())"/>
    </fx:Declarations>

    <s:HGroup width="100%" 
              horizontalAlign="center"
              verticalAlign="middle"
              textAlign="center">
        <s:Label text="ZIP code"/>
        <s:TextInput id="zip" text="90503"/>
        <s:Label text="Radius in miles"/>
        <s:TextInput id="miles" text="5"/>
        <s:Button label="GO!" click="button1_clickHandler(event)"/>
    </s:HGroup>
    <mx:DataGrid id="dg" width="100%" height="100%">
        <mx:columns>
            <mx:DataGridColumn dataField="zip" headerText="ZIP Code"/>
            <mx:DataGridColumn dataField="distance" headerText="{'Distance in Miles from '+zip.text}"/>
            <mx:DataGridColumn dataField="city" headerText="City"/>
            <mx:DataGridColumn dataField="state" headerText="State"/>
        </mx:columns>
    </mx:DataGrid>

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.rpc.events.ResultEvent;

            [Bindable]
            public var result:Array=new Array();

            protected function button1_clickHandler(event:MouseEvent):void
            {
                service.url="http://free-zipcode-maps.com/tools/zipcoderadius/extractzips2.cgi?Zip_Code="+zip.text+"&Miles="+miles.text;
                service.send();             
            }

            protected function service_resultHandler(event:ResultEvent):void
            {   
                //<textarea name="download" cols=65 rows=20>
                //ZIP Code  Distance in Miles from 90503    City    State
                //</textarea>
                var res:String=event.result.toString();
                var startString:String="ZIP Code    Distance in Miles from "+zip.text+" City    State";
                var start:int=res.search(startString)+startString.length+1;
                var end:int=res.search('</textarea>')-1;
                res=res.substring(start,end);

                var rows:Array=res.split("\n");             
                for each(var row:String in rows)
                {
                    var r:Array=row.split("\t");
                    result.push({zip:r[0],distance:r[1],city:r[2],state:r[3]});
                }

                dg.dataProvider=new ArrayCollection(result);
            }

        ]]>
    </fx:Script>


</s:Application>
0
source

Source: https://habr.com/ru/post/1757924/


All Articles