Google Reverse Geocoding API doesn't work on mobile internet

So i was able to get Google Geolocations and Geocoder API to work via desktop and on my phone when its connected to wifi, but when I disconnect from the wifi, geocoder doesn't display the results.

just to explain a bit more about what my code does, i use the geolocation APi to get lat/long values and then i use that output that is stored in a variable and i use it to get the city information using the reverse geocoding google API.

my code below is as follows

jQuery(function() {
      var GOOGLE_API_KEY = 'MY_KEY_HERE';
     var outlatlong = null;
      jQuery.ajax({
        url: 'https://www.googleapis.com/geolocation/v1/geolocate?key='+GOOGLE_API_KEY,
        data: JSON.stringify({ "considerIp": "true" }),
        type: 'POST',
        contentType: 'application/json',
        success: function(data) {
            
    outlatlong = [data.location.lat, data.location.lng].join(', ');
            
         
          if(data.location) {
            var out = [data.location.lat, data.location.lng].join(', ');
            jQuery('#gresponse').html(out);
           
    var urlTwo = "https://maps.googleapis.com/maps/api/geocode/json?latlng="+out+"&key=MY_KEY_HERE";
    jQuery.get(urlTwo).success(function(data) {
       var loc1 = data.results[0];
       var county, city;
         jQuery.each(loc1, function(k1,v1) {
            if (k1 == "address_components") {
               for (var i = 0; i < v1.length; i++) {
                  for (k2 in v1[i]) {
                     if (k2 == "types") {
                        var types = v1[i][k2];
                        if (types[0] =="sublocality_level_1") {
                            county = v1[i].long_name;
                            //alert ("county: " + county);
                        } 
                        if (types[0] =="locality") {
                           city = v1[i].long_name;
                           alert ("city: " + city);
                       } 
                     }
                  }          
               }
            }

         });
         jQuery('#lattie').html(city); 
        
        
    });
              
          } else {
            jQuery('#lattie').html('didnt work');
          }
        },
        error: function(e) {
          console.log('error!', JSON.parse(e.responseText));
        }
      });
        return outlatlong
    });

Any help or solution will help! thank you all! <3



from Recent Questions - Stack Overflow https://ift.tt/3dqHlcC
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations