J Castillo
J Castillo

Reputation: 3357

Adding location to Google Map on page load with Angular UI

Thanks to @AJoslin I now have a working google map using only AngularUI and AngularJS.

Unfortunately there are two things I can't figure out how to do which may have to do with Google Map API and my lack of understanding of.

When the map initially loads, I already have a location so I wish to load it with a marker already on it. How do I do that?

I also wish to set the ng-click="myMap.panTo(marker.getPosition()) not to a new marker but to the initial location, which is the only marker I would have since I'm removing the add marker functionality out, once I can figure this one out.

Here is the working jsfiddle

http://jsfiddle.net/jorgecas99/xMw6U/

Upvotes: 2

Views: 1467

Answers (1)

mojzis
mojzis

Reputation: 324

i think it should be achievable by setting the tilesloaded event, but didnt manage that way, so i ended up using a simple "trick", watching for myMap to appear.

  $scope.$watch('myMap', function(){
    $scope.setHome();
  });

  $scope.setHome = function() {
    $scope.homeMarker = new google.maps.Marker({
    map: $scope.myMap,
    position: $scope.mapOptions.center
  });
  }

Upvotes: 3

Related Questions