如何让放在谷歌地图的JSON结果?放在、地图、结果、JSON

由网友(小青春丶灬无限坑)分享简介:我创建使用HTML5和Java Script一个简单的应用程序。我想表现出任何一个城市的最近的地方所以我已经设置长,土地增值税的国家的。如果用户点击学校,我想告诉所有的学校名称最接近的长和LAT半径。如果用户单击教会我想说明最近的长和LAT半径所有教堂的名字。如果用户点击医院我想说明最近的长和LAT半径所有的医院名称。...

我创建使用HTML5和Java Script一个简单的应用程序。    我想表现出任何一个城市的最近的地方    所以我已经设置长,土地增值税的国家的。

如果用户点击学校,我想告诉所有的学校名称最接近的长和LAT半径。    如果用户单击教会我想说明最近的长和LAT半径所有教堂的名字。    如果用户点击医院我想说明最近的长和LAT半径所有的医院名称。等等。

我只有这个链接和样品相关的code:

https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AIzaSyC1BIAzM34uk6SLY40s-nmXMivPJDfWgTc $ .getJSON(https://maps.googleapis.com/maps/api/place/search/json?,{         位置: - 33.8670522,151.1957362         半径:500,         类型:食物,         名称:港,         传感器:假的,         键:AIzaSyC1BIAzM34uk6SLY40s-nmXMivPJDfWgTc         格式为:JSON     },     功能(数据){       $每个(data.results,功能(I,项目){       $(< IMG />中)。ATTR(src用户,results.name).appendTo(#图像);       如果(我== 3)返回false;     });   });

所以,我想改变得到地名。    起初我该怎么办?

解决方案

地图V3不支持回拨/ JSONP从一个jQuery获取/的getJSON此时

如何将谷歌地图的地图保存下来

http://www.quora.com/为什么-犯规的非谷歌 - 地图-API的支持,JSONP

这是说 - 如果你有耐心尝试寻找

的http://$c$c.google.com/intl/no-NO/apis/maps/documentation/javascript/services.html#Geocoding

要异步加载,你需要做的是这样的:

 函数loadScript(){
  VAR脚本= document.createElement方法(脚本);
  script.type =文/ JavaScript的;
  script.src =htt​​p://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize;
  document.body.appendChild(脚本);
}
 

的http:// code。 google.com/apis/maps/documentation/javascript/basics.html#Async

如果不是,这里是我的建议。

使用代理:

除非有人能找到新的资源,显示如何使用JSONP做到这一点(我只能找到资源,告诉我不支持它)的方式是编写一个代理。

本作品来自同一服务器

演示

HTML:

 < HTML>
< HEAD>
&所述;脚本的src =htt​​ps://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js>&所述; /脚本>
<脚本>
$(文件)。就绪(函数(){
  $ .getJSON(googleapijson.php?类型=食品,
    功能(数据,textStatus){
      $每个(data.results,功能(I,项目){;
       $(#地名)追加(I +:+ item.vicinity +'< BR />');
    });
  });
});
< / SCRIPT>
< /头>
<身体GT;
 < D​​IV ID =地名>< / DIV>
< /身体GT;
< / HTML>
 

PHP:

 < PHP

标题(内容类型:应用程序/ JSON);

/ **注意,你需要抓住和清理从参数
 * GET / POST请求,并建立自己的查询字符串:
 * /

$型= $ _GET [型]; //这需要清洁

$URL="https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=".$type."&name=harbour&sensor=false&key=AIzaSyC1BIAzM34uk6SLY40s-nmXMivPJDfWgTc"

$ JSON =的file_get_contents($网址);

回声$ JSON;
?>
 

I am creating a simple apps using html5 and java script. I want to show nearest places of any one city so already I set long and lat of a country.

If user click school I want to show all school names nearest of long and lat with radius. If user click church I want to show all church names nearest of long and lat with radius. If user click hospital I want to show all hospital names nearest of long and lat with radius. etc.

I only have this link and sample related code:

https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AIzaSyC1BIAzM34uk6SLY40s-nmXMivPJDfWgTc


$.getJSON("https://maps.googleapis.com/maps/api/place/search/json?",{
        location:"-33.8670522,151.1957362",
        radius: 500,
        types:'food',
        name: 'harbour',
        sensor: false,
        key: 'AIzaSyC1BIAzM34uk6SLY40s-nmXMivPJDfWgTc'
        format: "json"  
    },
    function(data) {
      $.each(data.results, function(i,item){
      $("<img/>").attr("src", results.name).appendTo("#images");
      if ( i == 3 ) return false;
    });
  }); 

so where I want to change to get place name. initially what do I do?

解决方案

Maps v3 does not support callback/JSONP from a jQuery get/getJSON at this time

http://www.quora.com/Why-doesnt-the-Google-Maps-API-support-JSONP

That said - if you have the patience try looking at

http://code.google.com/intl/no-NO/apis/maps/documentation/javascript/services.html#Geocoding

To load async, you need to do something like this:

function loadScript() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
  document.body.appendChild(script);
}

http://code.google.com/apis/maps/documentation/javascript/basics.html#Async

If not, here is what I suggest.

USING PROXY:

Unless someone can find a new resource that shows how to do this with jsonp (I could only find resources telling me it was not supported) a way is to write a proxy.

This works FROM THE SAME SERVER

DEMO

HTML:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
<script>
$(document).ready(function() {
  $.getJSON("googleapijson.php?type=food",
    function(data, textStatus){
      $.each(data.results,function(i, item) {;
       $("#placenames").append(i+':'+item.vicinity+'<br/>');
    });
  });
});
</script>
</head>
<body> 
 <div id="placenames"></div>
</body>
</html>

PHP:

<?PHP

header("Content-type: application/json");

/** note you need to grab and clean the parameters from the   
 *  get/post request and build your querystring:   
 */

$type = $_GET["type"]; // this needs to be cleaned

$URL="https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=".$type."&name=harbour&sensor=false&key=AIzaSyC1BIAzM34uk6SLY40s-nmXMivPJDfWgTc"

$json = file_get_contents($URL);

echo $json;
?>

阅读全文

相关推荐

最新文章