Javascript 获取谷歌地图上的当前位置-AngularJS

Javascript 获取谷歌地图上的当前位置-AngularJS,javascript,angularjs,asp.net-mvc,google-maps,Javascript,Angularjs,Asp.net Mvc,Google Maps,我正在尝试使用谷歌地图和AngularJS获取当前位置。 这是我的代码:- angular.module('indexAngularApp',['uiGmapgoogle-maps'])) .controller('mapsController',函数($scope,$http){ //这是地图首次加载时的默认坐标 变量选项={ EnableHighAccurance:正确 }; navigator.geolocation.getCurrentPosition(函数(pos)){ $scope

我正在尝试使用谷歌地图和AngularJS获取当前位置。 这是我的代码:-

angular.module('indexAngularApp',['uiGmapgoogle-maps']))
.controller('mapsController',函数($scope,$http){
//这是地图首次加载时的默认坐标
变量选项={
EnableHighAccurance:正确
};
navigator.geolocation.getCurrentPosition(函数(pos)){
$scope.map=new google.maps.LatLng(pos.coords.latitude,pos.coords.longitude);
$scope.map.center.latitude=新的google.maps.LatLng(pos.coords.latitude);
$scope.map.center.longitude=新的google.maps.LatLng(pos.coords.longitude);
$scope.map.center.zoom=15;
//$scope.position.latitude=28.699955;
//$scope.position.longitude=77.098159;
//变量a=$scope.position.latitude;
//var b=$scope.position.longitude;
//log(JSON.stringify($scope.map));
//$scope.map.center.latitude=$scope.position.latitude;
//$scope.map.center.longitude=data.data.Long;
//$scope.map=
//{
//中心:
//    {
//纬度:a,
//经度:b
//    },
//缩放:15
//}
},
函数(错误){
警报(“无法获取位置:”+错误消息);
},选项);
$scope.markers=[];
$scope.locations=[];
//从服务器获取所有位置
$http.get('http://localhost:4582/Api/NewCompWebAPI)。然后(函数(数据){
$scope.locations=data.data;
},函数(){
警报(“错误”);
});
//从服务器获取制造商信息的服务
$scope.ShowLocation=函数(locationID){
$http.get(“/home/GetMarkerData”{
参数:{
locationID:locationID
}
}).then(功能(数据){
$scope.markers=[];
$scope.markers.push({
id:data.data.LocationID,
协调:{
纬度:data.data.Lat,
经度:data.data.Long
},
title:data.data.title,//制造商名称
地址:data.data.address,//制造商地址
image:data.data.ImagePath//image--可选
});
//将贴图焦点设置为中心
$scope.map.center.lation=data.data.Lat;
$scope.map.center.longitude=data.data.Long;
},函数(){
警报('Error');//如果连接丢失或发生错误,则显示错误
});
}
//使用此处的选项在地图上显示或隐藏标记
$scope.windowOptions={
秀:真的
};
})
//mapsController在此结束
输入{
填充物:5px;
边框:1px实心#A5A5;
}
input.ng-dirty.ng-无效{
边框:1px纯红;
背景色:rgb(255244244);
}
.错误{
颜色:红色;
}
.google地图容器{
高度:300px;
盒影:2件2件3件3件浅灰色;
}
.谷歌地图{
宽度:80%;
身高:100%;
保证金:自动0px;
}

{{map.center}}
{{marker.title}

{{marker.address}
客户数量:



最后,我刚刚更改了IndesAngular.js文件:-

angular.module('indexAngularApp',['uiGmapgoogle-maps']))
.controller('mapsController',函数($scope,$http){
//这是地图首次加载时的默认坐标
变量选项={
EnableHighAccurance:正确
};
navigator.geolocation.getCurrentPosition(函数(pos)){
$scope.position=new google.maps.LatLng(pos.coords.lation,pos.coords.longitude);
$scope.map={
中心:
{
纬度:位置坐标纬度,
经度:位置坐标经度
},
缩放:17
};
//log(JSON.stringify($scope.map));
},
函数(错误){
警报(“无法获取位置:”+错误消息);
},选项);
//$scope.map=
//  {
//中心:
//      {
//纬度:28.6315,
//经度:77.6315
//      },
//缩放:16
//  }
$scope.markers=[];
$scope.locations=[];
//从服务器获取所有位置
$http.get('http://localhost:4582/Api/NewCompWebAPI)。然后(函数(数据){
$scope.locations=data.data;
},函数(){
警报(“错误”);
});
//从服务器获取制造商信息的服务
//$scope.ShowLocation=函数(locationID){
//$http.get(“/home/GetMarkerData”,
//    {
//参数:
//        {
//locationID:locationID
//        }
//})。然后(函数(数据){
//$scope.markers=[];
//$scope.markers.push
//        ({
//id:data.data.LocationID,
//协调:
//            {
//纬度:data.data.Lat,
//经度:data.data.Long
//            },
//标题: