angularjs-googleMap googleMap api地址解析与反解析

1.js:根据地址得到经纬度
var myplace=$scope.place;//获取输入的地址
var geocoder = new google.maps.Geocoder();//创建geocoder服务
//调用geocoder服务完成转换
geocoder.geocode( { 'address': myplace}, function(results, status) {
if (status==google.maps.GeocoderStatus.OK) {
lat=results[0].geometry.location.lat();
lng=results[0].geometry.location.lng();
address=results[0].formatted_address;
placeId = results[0].place_id;
//cacheAddress(placeId, lat, lng, address);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
}); 2.js:反解析,根据经纬度得到地址
fn.callBack=function(data){
if(data.status=="OK"){
var lat=data.results[0].geometry.location.lat;
var lng=data.results[0].geometry.location.lng;
var address=data.results[0].formatted_address;
var placeId=data.results[0].place_id;
if(vm.radius == null || vm.radius.length == 0){
alert("Please enter a radius.");
return;
}
if(vm.radius<=0){
alert("Radius must be greater than 0.");
return;
}
cacheAddress(placeId, lat, lng, address,vm.radius);
}
} $scope.showPosition = function (position) {
$scope.lat = position.coords.latitude;
$scope.lng = position.coords.longitude;
$scope.accuracy = position.coords.accuracy;
$scope.$apply();
$.ajax({
url: 'http://maps.google.com/maps/api/geocode/json?latlng='+$scope.lat+','+$scope.lng+'&language=en&sensor=false',
data: {},
dataType:'JSON',
success:function(data){
fn.callBack(data);
}
}); } $scope.showError = function (error) {
switch (error.code) {
case error.PERMISSION_DENIED:
$scope.error = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
$scope.error = "Location information is unavailable."
break;
case error.TIMEOUT:
$scope.error = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
$scope.error = "An unknown error occurred."
break;
}
$scope.$apply();
} $scope.getLocation = function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition($scope.showPosition, $scope.showError);
}
else {
$scope.error = "Geolocation is not supported by this browser.";
}
}
fn.locationMe=function(){
/*$scope.coords = geolocation.getLocation().then(function(data){
return {lat:data.coords.latitude, lng:data.coords.longitude};
});*/
/*console.log($scope.coords);31.2989513,121.5150925*/
$scope.getLocation();
} 3.总结:原文参考:http://blog.csdn.net/x1135768777/article/details/8156048 根据地址解析
https://maps.google.com/maps/api/geocode/json?address=chaoyango&sensor=true

根据经纬度解析

https://maps.googleapis.com/maps/api/geocode/json?latlng=39.988350,116.417152&sensor=true

传入起始经纬度得到路线

http://maps.google.com/maps/api/directions/json?origin=39.988350,116.417152&destination=39.999350,116.417152&sensor=true

or

https://maps.google.com/maps/api/directions/json?origin=罗马花园&destination=中关村&mode=driving&sensor=true

在线路中使用路标(从立水桥到朝阳罗马花园但是要经过知春路和鸟巢)

https://maps.googleapis.com/maps/api/directions/json?origin=立水桥&destination=朝阳罗马花园&waypoints=知春路|鸟巢&sensor=true

api:https://developers.google.com/maps/documentation/directions/?hl=zh-cn#Waypoints

google地图多地点线路查询

http://ditu.google.cn/maps?f=d&source=s_d&saddr=昌平&daddr=立水桥+to:知春路+to:*+to:西单+to:中关村&hl=zh-CN&geocode=china

根据placeId得到相关信息

https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyBVovr-ihWlP9N7rCCVDuNABKeCVR7xX8Y&place_id=ChIJByP4k1NYwokR7WYV3pZo1fc&sensor=true

java google map : http://blog.csdn.net/qiuzhping/article/details/39697111
上一篇:个人怎么申请微信小程序


下一篇:[APIO2012]派遣