{"id":7819,"date":"2015-10-30T01:25:01","date_gmt":"2015-10-30T01:25:01","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/10\/30\/cant-center-angularjs-google-map-use-of-angularjs-google-maps-api-open-source-projects-allenhwkim-angularjs-google-maps\/"},"modified":"2015-10-30T01:25:01","modified_gmt":"2015-10-30T01:25:01","slug":"cant-center-angularjs-google-map-use-of-angularjs-google-maps-api-open-source-projects-allenhwkim-angularjs-google-maps","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/10\/30\/cant-center-angularjs-google-map-use-of-angularjs-google-maps-api-open-source-projects-allenhwkim-angularjs-google-maps\/","title":{"rendered":"Can&#39;t center AngularJS Google Map \/ Use of AngularJS Google Maps API-open source projects allenhwkim\/angularjs-google-maps"},"content":{"rendered":"<p>I stumbled open Google Maps for AngularJS and thought it could be a good approach for working with google maps on a mobile cross-device app (I&#8217;m using the Ionic Framework). I&#8217;d like to load locations from a server, filter them, use custom markers and info bubbles, create routes with navigation steps, etc.<\/p>\n<p>I wonder why do I need this:<\/p>\n<pre><code>\n\n<\/code><\/pre>\n<p>since I&#8217;m already able to do the stuff I intend to using only the Google Maps API (without Ionic or Angular, though).<\/p>\n<p>Actually, using the Google Maps for AngularJS method, I&#8217;m running through some issues, for example, this doesn&#8217;t work:<\/p>\n<p><code>$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));<\/code><\/p>\n<p>It returns <code>Uncaught TypeError: undefined is not a function<\/code><\/p>\n<p>This does not work either:<\/p>\n<p><code>$scope.map.control.refresh({latitude: pos.coords.latitude, longitude: pos.coords.longitude});<\/code><\/p>\n<p>It returns: <code>Uncaught TypeError: Cannot read property 'refresh' of undefined<\/code><\/p>\n<p>Here&#8217;s the code from the controller:<\/p>\n<pre><code>.controller('MapCtrl', function($scope) {\n\n  $scope.map = {\n    center: {\n        latitude: 45,\n        longitude: -73\n    },\n    zoom: 8\n    };\n\n  $scope.centerMap = function () {\n    if (!$scope.map) {\n      return;\n    }\n\n    navigator.geolocation.getCurrentPosition(function (pos) {\n      \/\/console.log('Got pos', pos.coords.latitude, \", \", pos.coords.longitude); \/\/ ok\n      \/\/$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));     \/\/ does not work\n      \/\/$scope.map.control.refresh({latitude: pos.coords.latitude, longitude: pos.coords.longitude});   \/\/ does not work\n\n    }, function (error) {\n      alert('Unable to get location: ' + error.message);\n    });\n  };\n})\n<\/code><\/pre>\n<p>And inside the view:<\/p>\n<pre><code>\n\n<\/code><\/pre>\n<p>I know the obvious, philosophical answer is: &#8220;if you don&#8217;t need it don&#8217;t use it&#8221; but I feel I&#8217;m missing some basic stuff here and I want to have a deeper understanding on the subject.<\/p>\n<p>Any help will be greatly appreciated.<\/p>\n<p>ps:<\/p>\n<p>i&#8217;m very new to Angular (and many concepts it relies on), so that&#8217;s probably the main reason behind my confusion. if there&#8217;s anything wrong with this post (too vague, or i&#8217;m too lazy) i&#8217;d be happy to be notified.<\/p>\n<p>ps 2:<\/p>\n<p>I got it to work using:<\/p>\n<p>$scope.map.center.latitude = 45; $scope.map.center.longitude = -74;<\/p>\n<p>I don&#8217;t understand why the following example, as in AngularGoogleMaps API docs, doesn&#8217;t work for me:<\/p>\n<p><code>$scope.map.control.refresh({latitude: 32.779680, longitude: -79.935493});<\/code><\/p>\n<p>Actually <code>$scope.map.control<\/code> returns <code>undefined<\/code> in my code.<\/p>\n<p>ps 3:<\/p>\n<p>I actually have 2 questions in one here: one about centering the map and another vague one about the use of the AngularJS Google Maps API, for which I had great answers &#8211; so, sorry for the mess, I&#8217;m deleting this thread.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I stumbled open Google Maps for AngularJS and thought it could be a good approach for working with google maps on a mobile cross-device app (I&#8217;m using the Ionic Framework). I&#8217;d like to load locations from a server, filter them, use custom markers and info bubbles, create routes with navigation steps, etc. I wonder why [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7819","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7819"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7819\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}