Information Technology Questions and Answers Community

Questions/Title


   Asked Questions

Views
88
Answers
1
Action
Views
98
Answers
1
Action
Views
106
Answers
1
Action
Views
107
Answers
1
Action
Views
157
Answers
0
Action

I pull a list of areas to display on a google maps from my database. I would also like to show the city closest to each area using reverse geocoding but cannot get it to work. I have some experience with AngularJS and promises and have searched Stackoverflow but cannot find any solution to this problem.

HTML:

<div ng-repeat="area in vm.areas">
 <span>{{area.name}}</span>
 <span>Close to: </span> <span>{{vm.getCity(area)}}</span>
</div>

JS:

vm.getCity = function(area){
 var center = getCenter(area.paths); 
 getAddress(center[0], center[1]).then(function(city){
   console.log(city);
   return city;
 })
}

function getAddress (latitude, longitude) {
  return $q(function (resolve, reject) {
      var request = new XMLHttpRequest();

      var method = 'GET';
      var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&sensor=true';
      var async = true;

      request.open(method, url, async);
      request.onreadystatechange = function () {
          if (request.readyState == 4) {
              if (request.status == 200) {
                  var data = JSON.parse(request.responseText);
                  var results = data.results;
                  var returnString = ""
                  for(var i=0; i<results.length; i++){
                    var types = results[i].types;
                    if(types[0] === 'locality'){
                      returnString = results[i].address_components[0].long_name;
                    }
                  }
                  resolve(returnString);
              }
              else {
                  reject(request.status);
              
JavaScript  
angular-js  
google-maps  
google-maps-api-3  
Date Posted:06 Sep at 07:13  Posted By:0 
Views
82
Answers
0
Action

I pull a list of areas to display on a google maps from my database. I would also like to show the city closest to each area using reverse geocoding but cannot get it to work. I have some experience with AngularJS and promises and have searched Stackoverflow but cannot find any solution to this problem.

HTML:

<div ng-repeat="area in vm.areas">
 <span>{{area.name}}</span>
 <span>Close to: </span> <span>{{vm.getCity(area)}}</span>
</div>

JS:

vm.getCity = function(area){
 var center = getCenter(area.paths); 
 getAddress(center[0], center[1]).then(function(city){
   console.log(city);
   return city;
 })
}

function getAddress (latitude, longitude) {
  return $q(function (resolve, reject) {
      var request = new XMLHttpRequest();

      var method = 'GET';
      var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&sensor=true';
      var async = true;

      request.open(method, url, async);
      request.onreadystatechange = function () {
          if (request.readyState == 4) {
              if (request.status == 200) {
                  var data = JSON.parse(request.responseText);
                  var results = data.results;
                  var returnString = ""
                  for(var i=0; i<results.length; i++){
                    var types = results[i].types;
                    if(types[0] === 'locality'){
                      returnString = results[i].address_components[0].long_name;
                    }
                  }
                  resolve(returnString);
              }
              else {
                  reject(request.status);
              
JavaScript  
angularjs  
google-maps  
google-maps-api3  
Date Posted:06 Sep at 07:09  Posted By:0 
Views
84
Answers
0
Action
Edit Account
LOGIN INFORMATION
Change Settings
Email Notifications Notifications will be sent to abcd@gmail.com
Select option for your email notifications:
Mature / News Filter We'll send on email when new jobs are posted
Option 2 for email notification We'll send on email when new jobs are posted