Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用pin码查找给定区域的lat、long_Javascript_Ajax_Bing - Fatal编程技术网

Javascript 如何使用pin码查找给定区域的lat、long

Javascript 如何使用pin码查找给定区域的lat、long,javascript,ajax,bing,Javascript,Ajax,Bing,嗨,我在我的网站上使用Bing地图,希望lat long在Bing地图上精确定位那个位置。我的问题是在我的网站上,如何使用pincode获得一个区域的lat-long。是否有任何api,我可以使用它通过提供区域pin码来查询lat long。我想在后台做。使用ajax调用特定的webapi,返回lat lang并将其保存到数据库中,这样我就可以使用lat long在我的bing地图上绘制位置 我正在使用BingMap7,我需要将lat-long值放入json对象中,并将其传递到BingMap中

嗨,我在我的网站上使用Bing地图,希望lat long在Bing地图上精确定位那个位置。我的问题是在我的网站上,如何使用pincode获得一个区域的lat-long。是否有任何api,我可以使用它通过提供区域pin码来查询lat long。我想在后台做。使用ajax调用特定的webapi,返回lat lang并将其保存到数据库中,这样我就可以使用lat long在我的bing地图上绘制位置

我正在使用BingMap7,我需要将lat-long值放入json对象中,并将其传递到BingMap中

function GetMap()
{
var mapOptions = {
credentials: "Your Bing Maps Key",
center: new Microsoft.Maps.Location(47.592, -122.332), // i want these value in my         database 
mapTypeId: Microsoft.Maps.MapTypeId.birdseye,
zoom: 17,
showScalebar: false
}
var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions);
}  
我可以硬编码,但在我的应用程序中,我给了客户端一个选项,用于添加新位置,所以在后端,我希望它就像客户端添加任何新位置时,它也会自动保存其lat long一样


感谢

Geonames是一项适用于所有位置信息的良好服务,请查看他们提供的服务列表:


你能用这个查一下邮政编码吗?api.geonames.org/postalcodeokupjson?postalcode=6600&country=AT&username=demo

使用pincodes获取lat,long值可能不是最好的解决方案,因为pin码虽然流行了一个多世纪,但仍然在世界各地流行。例如,在美国,pincode(邮政编码)通常有5位数字(即06160),而在我所在的地区,它们通常有6位或更多

尽管你可以使用街道地址、州、国家和pin码的组合来找出世界上几乎每个地方几乎正确的地理坐标。请参阅下面的脚本,该脚本调用GoogleAPI来查找Lat、Long值。。。在此,我根据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>

var地理编码器,位置1;
函数初始化(){
geocoder=新的GClientGeocoder();
}
函数prepareQuery(){
var查询=“”;
var a1=document.getElementById('address1')。值;
var a2=document.getElementById('address2')。值;
var a3=document.getElementById('address3')。值;
var cty=document.getElementById('city')。值;
var stat=document.getElementById('state')。值;
var cntry=document.getElementById('country')。值;
var pin=document.getElementById('pincode')。值;
如果(a1!=null&&a1!=''){
query=query+a1+“,”;
}
如果(a2!=null&&a2!=''){
query=query+a2+“,”;
}
如果(a3!=null&&a3!=''){
查询=查询+a3+“,”;
}
如果(cty!=null&&cty!=''){
query=query+cty+“,”;
}
if(stat!=null&&stat!=''){
query=query+stat+“,”;
}
如果(cntry!=null&&cntry!=''){
query=query+cntry+“,”;
}
if(pin!=null&&pin!=''){
查询=查询+pin+“,”;
}
//警报(“准备查询返回”+查询);
返回查询;
}
函数submitFunc(){
变量位置=prepareQuery();
geocoder.getLocations(位置、功能(响应){
如果(!response | | response.Status.code!=200)
{
警报(“对不起,我们无法对地址进行地理编码”);
}
其他的
{                     
location1={纬度:响应。地点标记[0]。点。坐标[1],经度:响应。地点标记[0]。点。坐标[0],地址:响应。地点标记[0]。地址};
var项目=[];
$.each(位置1,函数(键,值){
items.push(“
  • “+key+”:“+value+”
  • ”); }); //警报(项目) $(“正文”)。追加(“结果为:-”); $(“
      ”{ “类”:“我的新列表”, html:items.join(“”) }).附于(“主体”); } }); }
    html看起来像

            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>
    
    第1行:

    第2行:

    第3行:

    城市:

    状态:

    国家:

    Pin码:



    您的结果将显示在此处
    我已经使用谷歌api完成了这项工作,但我不确定您是否想要基于谷歌的解决方案。因为您正在使用bing api。如果你想要基于谷歌的代码,我可以分享…请分享。您是否正在使用其他api或web服务从pin码中查找lat long。您也可以尝试使用此api或web服务。谢谢您的帮助,但我没有从中获得任何api或示例代码。请您分享一些代码或任何其他链接,我可以从中获得任何教程,谢谢我使用了这个链接api.geonames.org/postalcodeokupjson?postalcode=6600&country=AT&username=demo,但它对我不起作用