Google API无法使用其他纬度和经度

时间:2012-03-06 04:47:16

标签: google-maps-api-3 google-places-api

我想在我的项目中使用google API。 我得到的是来自here

APi是: - https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=5000&types=food&sensor=false&key= * ** * ** * ** * ** * ** * ***

注意: - 我在此网址末尾添加了我的KEY。它向我展示了正确的反应。 但是,如果我改变纬度和经度到古吉拉特邦(国家印度)..然后它没有给我任何回应。 如果ZERO_RESULT

,则为响应

任何人都可以帮助我为什么会这样,以及如何解决它。

我想这样做是为了获取当前latitide -itude的附近信息.. 有没有其他方式或api获取附近地区的信息.. 请帮我.. 提前致谢

2 个答案:

答案 0 :(得分:1)

如果给定坐标(纬度和经度)周围没有给定半径的寄存器位置,则API将响应ZERO_RESULT

获得结果

  • 指定正确的坐标(当前位置)
  • 半径限制,最大允许半径为50000米= 50公里

以下网址正在运行 - 距离古吉拉特邦(指定坐标)30公里范围内的食物类型。

https://maps.googleapis.com/maps/api/place/search/json?location=23.0,72.0&radius=30000&types=food&sensor=false&key= [API密钥]

答案 1 :(得分:1)

我使用了这个代码段,它适用于所有情况。

<body>
<div id="mainpanel" style="float:left; background-color:#fff; width:75%;">
    <div style="display:none;" id="lat">hhh</div><div style="display:none;" id="lon">hhh</div>


<script>
var x=document.getElementById("lat");
var y=document.getElementById("lon");
function getLocation()
  {
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
function showPosition(position)
  {
  x.innerHTML=position.coords.latitude; 
  y.innerHTML=position.coords.longitude;
  loadScript();
  }

function initialize()
{
var xval=document.getElementById("lat").innerHTML;
var yval=document.getElementById("lon").innerHTML;
var mapProp = {
   center: new google.maps.LatLng(xval,yval),
    zoom:7,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
}

function loadScript()
{
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false&callback=initialize";
  document.body.appendChild(script);
}
//window.onload = loadScript;
</script>
    <form>
        <input class="boxinput" type="text" class="form-control" placeholder="Phone" id="" name=""/>
        </form>
    <div class="serchbox"></div>
    <div id="googleMap" style="width:960px;height:804px;"></div>

    </div>  
     </body>