Skip to content Skip to sidebar Skip to footer

How To Find Lat ,long Of A Given Area Using Pin Code

hi i am using Bing map in my website and want lat long to pinpoint that location on Bing map. my question is in my website how can i get lat long of an area using pincode. Is there

Solution 1:

Using pincodes for obtaining the lat, long values may not be the best solution, since pin codes though popular for more than a century are still not a standard round the world. for example in US pincodes (zip codes) are normally have 5 digits (i.e. 06160) and in my part of the world their are normally 6 digits or more..

Though you can use combination of street address, state, country and pin code to find out the nearly correct geo coordinates for almost every part of the world. See following script which calls google api for finding the Lat, Long value... Here by I donate this code to the community under GPL:-

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"> </script>

<script src="http://maps.google.com/maps?file=api&v=3&key=ABQIAAAA7j_Q-rshuWkc8HyFI4V2HxQYPm-xtd00hTQOC0OXpAMO40FHAxT29dNBGfxqMPq5zwdeiDSHEPL89A" type="text/javascript"> </script>
 <script type="text/javascript">

        var geocoder, location1;

        function initialize() {
            geocoder = new GClientGeocoder();
        }
        function prepareQuery(){
            var query='';
            var a1 = document.getElementById('address1').value;
            var a2 = document.getElementById('address2').value;
            var a3 = document.getElementById('address3').value;
            var cty = document.getElementById('city').value;
            var stat = document.getElementById('state').value;
            var cntry =document.getElementById('country').value;
            var pin = document.getElementById('pincode').value;

            if(a1 != null && a1!=''){
                query = query + a1 + ",";                    
            }
            if(a2 != null && a2!=''){
                query =query + a2 + ",";                    
            }
            if(a3 != null && a3!=''){
                query = query + a3 + ",";                    
            }
            if(cty != null && cty!=''){
                query = query + cty + ",";                    
            }
            if(stat != null && stat!=''){
                query = query + stat + ",";                    
            }
            if(cntry != null && cntry!=''){
                query = query + cntry + ",";                    
            }
            if(pin != null && pin!=''){
                query = query + pin + ",";                    
            }
            //                alert("Prepare Query Returns " +query);
            return query;
        }
        function submitFunc(){
            var location = prepareQuery();               
            geocoder.getLocations(location, function (response) {
                if (!response || response.Status.code != 200)
                {
                    alert("Sorry, we were unable to geocode the address");
                }
                else
                {                     
                    location1 = {latitude: response.Placemark[0].Point.coordinates[1], longitude: response.Placemark[0].Point.coordinates[0], Address : response.Placemark[0].address};

                    var items = [];
                    $.each(location1, function(key, value){                          
                        items.push('<li id="' + key + '">' + key +" : "+ value + '</li>');
                    });
                    //                        alert(items)
                    $("body").append("Results is :-");
                    $('<ul/>', {
                        'class': 'my-new-list',
                        html: items.join('')
                    }).appendTo('body');
                }
            });
        }

    </script>

and the html looks like....

        Line 1   : <input type="text" id="address1" value="" placeholder="Enter first line of address."/> <br></br>               
        Line 2   :<input type="text" id="address2" value="" placeholder="Enter second line of address."/> <br></br>               
        Line 3   :<input type="text" id="address3" value="" placeholder="Enter third line of address."/> <br></br>               
        City     : <input type="text" id="city" value="" placeholder="Enter city name."/> <br></br>               
        State    : <input type="text" id="state" value="" placeholder="Enter state name."/> <br></br>               
        Country  : <input type="text" id="country" value="" placeholder="Enter country name."/> <br></br>               
        Pin Code : <input type="text" id="pincode" value="" placeholder="Enter pincode value."/> <br></br>               
        <input type="button" name="submitBtn" value="submit" onclick='submitFunc();'/> <br></br>

        <h3> <strong> Your Results Will be displayed Here . . . .</strong> </h3>

Solution 2:

Geonames is a good service for all kind of location stuff, take a look at the list of the services they provide:

http://www.geonames.org/export/ws-overview.html

Could you use the one to look up postal codes? api.geonames.org/postalCodeLookupJSON?postalcode=6600&country=AT&username=demo


Post a Comment for "How To Find Lat ,long Of A Given Area Using Pin Code"