Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have a form where a user clicks on google map and the latitude and longitude are shown in a text box.

function addMarker(location) {
  document.getElementById('hLat').value = location.lat().toPrecision(8);
  document.getElementById('hLong').value = location.lng().toPrecision(8);  
}

The text boxes are defined as

<input type="text"  id = "hLat" name = "hLat" ng-model="form.latitude"/>
<input type="text"  id = "hLong" name = "hLong" ng-model="form.longitude"/>

In the above way, the $scope.formDetails.latitude is comes as undefined in the controller and a 404 error is received. Though the latitude and longitude values are displayed in the text box.

While if I do

 document.getElementById('hLat').value = "25.6";
 document.getElementById('hLong').value = "45.6";  

the output is 25.6 and the function executes successfully.

My controller is defined a follows:

var app = angular.module('myApp', []);
app.controller('FormCtrl', function ($scope, $http) {

    $scope.formData = {
        epic: "default"

    };

    $scope.formDetails = {

        latitude: "default",
        longitude: "default"

    };


    $scope.save = function() {
        formData = $scope.form;
    };

        $scope.submitDetails = function() {
        console.log("posting data....");
        $scope.formDetails = $scope.form;
        document.write($scope.formDetails.latitude); // strange behaviour
        $http({method:'GET', url:'http://localhost/nametestjson.php', params:{search_type:"details", latitude:$scope.formDetails.latitude, longitude:$scope.formDetails.longitude, page_no:"1", results_per_page:"15"}}).success(function(data){        
            $scope.friends = data.response.docs;        
            var str = JSON.stringify(data, undefined, 2);       
            alert("success");
        }).error(function(data, status, headers, config) {

            alert(status);
            });           
    };

});
share|improve this question
    
addMarker should be a controller method working on the scope variable – apneadiving Feb 27 '14 at 7:38
    
thanks. But I am not sure how to add that function since my google maps api is being loaded from the normal javascript – krammer Feb 28 '14 at 5:55

I have this same issue no of day's before

function addMarker(location) {
  document.getElementById('hLat').value = location.lat().toPrecision(8);
  document.getElementById('hLong').value = location.lng().toPrecision(8);  
}

Currently your are using angularjs, so why u wrote pure javascipt coding?? Please try this

function addMarker(location) {
      $scope.form.latitude= location.lat().toPrecision(8);
      $scope.form.longitude= location.lng().toPrecision(8);  
      $scope.$apply();
    }
share|improve this answer
    
But I get $scope not defined when adding it to addMarker – krammer Feb 27 '14 at 8:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.