Angular Js & google maps API ngGeolocation
NickName:Stacca Ask DateTime:2015-05-19T23:37:10

Angular Js & google maps API ngGeolocation

I am having trouble getting a marker to display my geolocation on google maps api.

I am using the ng controller ngGeolocation & the http://angular-ui.github.io/angular-google-maps/

I had no troubles when I hardcoded the marker and map location. But as soon as I changed the controller the map disappeared.

Any help greatly appreciated

My controller

'use strict';

angular.module('fiveMinCatchupApp')
.controller('MainCtrl', function ($scope, uiGmapGoogleMapApi) {

var scope = $scope;
var lat; 
var lng

function getLocation() {
navigator.geolocation.getCurrentPosition($scope.showLocation);
};

$scope.showLocation = function(position){
  lat = position.coords.latitude;
  lng = position.coords.longitude;
  $scope.map = {
  center: {
    latitude: position.coords.latitude,
    longitude: position.coords.longitude,
  },
  zoom: 8
}

};

getLocation();

Main html

<ui-gmap-google-map center="map.center" zoom="map.zoom">
<ui-gmap-markers 
models='markers'
coords="'coords'"> 
</ui-gmap-markers>
</ui-gmap-google-map>

HTML

<body ng-app="fiveMinCatchupApp">


<div class="container">
<div ng-view=""></div>
</div>

<div class="footer">
  <div class="container">
    <p><span class="glyphicon glyphicon-heart"></span> from the Yeoman team</p>
  </div>
</div>


<!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
 <script>
   !function(A,n,g,u,l,a,r){A.GoogleAnalyticsObject=l,A[l]=A[l]||function(){
   (A[l].q=A[l].q||[]).push(arguments)},A[l].l=+new Date,a=n.createElement(g),
   r=n.getElementsByTagName(g)[0],a.src=u,r.parentNode.insertBefore(a,r)
   }(window,document,'script','//www.google-analytics.com/analytics.js','ga');

   ga('create', 'UA-XXXXX-X');
   ga('send', 'pageview');
</script>

<script src='//maps.googleapis.com/maps/api/js?sensor=false'></script>

<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-touch/angular-touch.js"></script>
<script src="bower_components/lodash/dist/lodash.compat.js"></script>
<script src="bower_components/angular-google-maps/dist/angular-google-maps.js"></script>
<script src="bower_components/ngGeolocation/ngGeolocation.js"></script>
<!-- endbower -->
<!-- endbuild -->

    <!-- build:js({.tmp,app}) scripts/scripts.js -->
    <script src="scripts/app.js"></script>
    <script src="scripts/controllers/main.js"></script>
    <script src="scripts/controllers/about.js"></script>
    <!-- endbuild -->

Thanks!

Previous version hardcoded on github at https://github.com/5-minute-catchup/5-min-catchup/commit/2899e013a78e93016154f1bd7d462b83f414db7e

Copyright Notice:Content Author:「Stacca」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30330109/angular-js-google-maps-api-nggeolocation

More about “Angular Js & google maps API ngGeolocation” related questions

Implement Angular js website sidebar in angular js

I am implementing angular js sidebar from https://material.angularjs.org as said Create a menu like in AngularJs Material website The "Component" is found in componentsData.js process But file re...

Show Detail

Angular js error

On including the jquery file prior to angular js file ,angular js is giving the following error,actually I was working with the reverse order, to create a date-picker directive I have to use the js...

Show Detail

Angular js to angular 5 migration

I am trying to migrate my angularjs(1.6) to angular 5. As of now I am focusing over migration of one page and want to go for both frameworks angular js and angular 5 running in same application. I...

Show Detail

JS Error with Angular JS Module

I wrote a Module to keep track of all my helper functions (scripts/apps.js): angular.module('app', ['ngResource']).run(function($scope){ $scope.UTIL = { setup_pod_variables: function (pods){...}...

Show Detail

Ionic 1 with Angular JS 1 or Angular JS 2

I am a beginner in hybrid app development. I know there is Ionic version 1 and 2(unofficial release). There is also a Angular JS version 1 and 2 (unofficial release). The following are my questions...

Show Detail

Angular JS and Django

This might be a silly question that might relate to my ignorance about angular js, but is it possible to use a Django framework mostly for backend and database interactions, in conjunction with an

Show Detail

Angular JS multiple errors

This is my situation: I setted up angular on HTML5 mode for urls, then, I'm using this .htaccess to handle the urls: RewriteEngine on # Don't rewrite files or directories RewriteCond %{

Show Detail

angular.js loaded instead of angular.min.js with requirejs

I'm using Webjars to import AngularJS into my web project. For some reason the minified version of AngularJS won't be served even though I'm referencing those in my main. I was expecting to see an...

Show Detail

Working with Angular js, Node js server and express js

So, I have a welcome page with sign in button which loads a Modal form built on Angular Js. It works fine when I run the welcome.html page as a standalone page on Google Chrome. Now, I've created a

Show Detail

$location is undefined in angular js with require js

I am bit new to angular js. Here I am trying to use angular js with require js. While configuring it I am getting a weird undefined error for $location while the error has not occurred for $scope. ...

Show Detail