-
-
Save zhangolve/e146ae1a1c6cf8e177404ae1f01f271d to your computer and use it in GitHub Desktop.
input-latlng-get-geo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<h1>输入经纬度值</h1> | |
<br><p>latitude</p> | |
<input id="latitude"> </input> | |
<br> | |
<p>longitude</p> | |
<input id="longitude"> </input> | |
<br> | |
<button class="btn btn-primary" onclick="searchIt()"> Enter</button> | |
<br> | |
<P>地址是:</P><p id="city"> </p> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function searchIt() | |
{ | |
var latitude=$("#latitude").val(); | |
var longitude=$("#longitude").val(); | |
if(latitude===null||latitude===undefined||longitude===''||longitude===null||longitude===undefined||longitude===''){ | |
alert("please input latitude and longitude"); | |
} | |
else | |
{ | |
var url="https://maps.googleapis.com/maps/api/geocode/json?latlng="+latitude+","+longitude+"&key=AIzaSyBUmxn8RqqIs74jh1wRup-FxpYNBUht4wg&sensor=true" | |
} | |
//使用alert()方法可以用来调试buG. | |
$(function(){ | |
alert(url); | |
// var //url='https://maps.google.com/maps/api/geocode/json?latlng='+latlng+'&key=AIzaSyBUmxn8RqqIs74jh1wRup-FxpYNBUht4wg&sensor=true' | |
$.ajax({ | |
type:"GET", | |
url:url | |
// dataType:'jsonp' 不能使用jsonp这样的数据类型在这里。 | |
}) | |
.done(function(data){ | |
var city=data.results[0].formatted_address | |
//状态码用于判断是否正常很好用 | |
$("#city").html(city); | |
}) | |
.fail(function(data){ | |
alert("failed") | |
}) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body{ | |
text-align:center; | |
} | |
p{ | |
font-size:30px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment