javascript - Returning the latitude and longitude of a default marker taken from string location -
my question how take latitude , longitude of existing marker? let me explain: when enter on page on browser display marker position using address:
<ng-map ng-if="null != evaluation" default-style="false" zoom="16" center="{{ '{{ getaddress() }}' }}" style="width: 100%; height: 430px;"> <marker centered="true" position="{{ '{{ getmarkerposition() }}' }}" draggable="true" on-dragend="onmarkerdragend($event)"></marker> </ng-map>
angular part:
$scope.getmarkerposition = function () { if (!$scope.address.mappinlocationlatitude || !$scope.address.mappinlocationlongitude) { return $scope.getaddress(); } return [$scope.address.mappinlocationlatitude, $scope.address.mappinlocationlongitude] }; $scope.getaddress = function () { //building adress getting objects used creating address object return streetstring + ', ' + address; //streetstring string has complete address }; $scope.onmarkerdragend = function ($event) { $scope.address.mappinlocationlatitude = $event.latlng.lat(); $scope.address.mappinlocationlongitude = $event.latlng.lng(); uptaderegions(); };
if move marker lat , log exists, method getmarkerposition returning array 2 of it. if don't move marker on map, how obtain lat , long? default 0 , don't know how resolve it. thank you,
edit:
app.controller('mapcontroller', ['$scope', 'ngmap','$state', 'selectoptionsservice', '$rootscope', '$q','geocoder', function ($scope, ngmap, $state, selectoptionsservice, $rootscope, $q, geocoder) {
so use address marker position, , want lat & lng during it's initialized? use geocoder
service (provided ngmap)
something like:
app.controller('mapcontroller', ['$scope', 'ngmap','$state', 'selectoptionsservice', '$rootscope', '$q','geocoder', function ($scope, ngmap, $state, selectoptionsservice, $rootscope, $q, geocoder) { //hired marker:geo-callback $scope.geocallback = function() { geocoder.geocode({ address: $scope.getaddress() }).then(function(result) { //explore this, may got position in: result[0].geometry.location console.log('a place object is: ', result); }); }; ... //your getaddress function $scope.getaddress = function() { }; }]);
and in html, in marker can use geo-callback
attribute
<marker ... geo-callback="geocallback()"></marker>
read geo-callback here
Comments
Post a Comment