aan*_*ain 2 javascript google-maps angularjs angularjs-directive
我对角度很新,并且正试图刺破角谷歌地图.
我的要求.我有一个搜索栏,用于搜索餐馆.搜索结果api给出了用户搜索的餐馆的地址,纬度和经度.我想要的是显示一个标记映射餐厅在地图上的位置.
我试过https://github.com/nlaplante/angular-google-maps/.它渲染地图,但不会将地图居中到纬度和我想要的长度.显然我试图从搜索API中映射lat和long
我想知道是否有人有类似我的用例并且有一个我可以遵循的例子.
感谢帮助.
更新:下面的链接似乎已经死了.使用这个:http://angular-ui.github.io/angular-google-maps/#!/
这听起来像是你要求的例子:http://nlaplante.github.io/angular-google-maps/#!/demo
看一下DemoController的来源(http://nlaplante.github.io/angular-google-maps/js/demo-controller.js):
module.controller("DemoController", function ($scope, $location) {
$scope.$watch("activeTab", function (newValue, oldValue) {
if (newValue === oldValue) {
return;
}
if ($location.path() != $scope.activeTab) {
$location.path($scope.activeTab);
}
});
$scope.getNavClass = function (item) {
return item == $scope.activeTab ? "active" : "";
};
// default location
$scope.center = {
latitude: 45,
longitude: -73
};
$scope.geolocationAvailable = navigator.geolocation ? true : false;
$scope.latitude = null;
$scope.longitude = null;
$scope.zoom = 4;
$scope.markers = [];
$scope.markerLat = null;
$scope.markerLng = null;
$scope.addMarker = function () {
$scope.markers.push({
latitude: parseFloat($scope.markerLat),
longitude: parseFloat($scope.markerLng)
});
$scope.markerLat = null;
$scope.markerLng = null;
};
$scope.findMe = function () {
if ($scope.geolocationAvailable) {
navigator.geolocation.getCurrentPosition(function (position) {
$scope.center = {
latitude: position.coords.latitude,
longitude: position.coords.longitude
};
$scope.$apply();
}, function () {
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
您可以使用$ scope.center告诉地图在哪里居中.
希望这可以帮助!
归档时间: |
|
查看次数: |
8586 次 |
最近记录: |