Sondes Sondes - 3 months ago 17x
AngularJS Question

AngularJS show pre defined coordinates of user on the map

I would show pre defined coordinates of user on the map when I logged it,this is my map


<!DOCTYPE html>
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/" rel="stylesheet">

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<script src=""></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/directives.js"></script>
<body ng-app="starter" ng-controller="MapCtrl">
<ion-header-bar class="bar-stable">
<h1 class="title">Map</h1>

<ion-content scroll="false">
<map on-create="mapCreated(map)"></map>

<ion-footer-bar class="bar-stable">
<a ng-click="centerOnMe()" class="button button-icon icon ion-navigate"></a>

and this is my controller


angular.module('starter.controllers', [])
.controller('MapCtrl', function($scope, $ionicLoading, $cordovaGeolocation) {
$scope.mapCreated = function(map) {
$scope.centerOnMe = function () {
if (!$ {
$scope.loading = ${
content: 'Getting current location...',
showBackdrop: false
navigator.geolocation.getCurrentPosition(function (pos) {
console.log('Got pos', pos);
$ google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
}, function (error) {
alert('Unable to get location: ' + error.message);
.controller('MapCtrl', function ($scope,geolocation) {
$scope.coords = {lat:data.coords.latitude, long:data.coords.longitude};

what should I add to pre defined location of any user in database.
Thinks in advance


If you want to just set the map to same position for all users then you can do:

var lat = 51.123456;
var lgt = 5.123456;
$ google.maps.LatLng(lat, lgt));

If you want to set it to location defined for each user separately then first access the DB and get latitude and longitude for user and set there.

If I understand your question right, then you don't need navigator.geolocation.getCurrentPosition at all as you don't want to use location provided by the browser.


Your question about getting data is very broad but the general idea is as follows. You need to create some service that handles database (for example dataService) and you can use it to set map:

dataService.loadUser(currentUserId).then(function(data) {
    $ google.maps.LatLng(data.latitude, data.longitude));

This shows that you also need to know what is the id or username or whatever identity you use of current user.