0 Replies - 1385 Views - Last Post: 24 March 2016 - 06:43 AM

#1 Desertt   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 182
  • Joined: 27-October 13

geolocation change language

Posted 24 March 2016 - 06:43 AM

Hi i am using this script to get the city name from long and lat

function displayLocation(latitude,longitude){
        var request = new XMLHttpRequest();

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

        request.open(method, url, async);
        request.onreadystatechange = function(){
          if(request.readyState == 4 && request.status == 200){
            var data = JSON.parse(request.responseText);
            var address = data.results[0];
            alert(address.formatted_address);
          }
        };
        request.send();
      };

      var successCallback = function(position){
        var x = '<?php echo $latitude;?>';
        var y = '<?php echo $longitude;?>';
        displayLocation(x,y);
      };

      var errorCallback = function(error){
        var errorMessage = 'Unknown error';
        switch(error.code) {
          case 1:
            errorMessage = 'Permission denied';
            break;
          case 2:
            errorMessage = 'Position unavailable';
            break;
          case 3:
            errorMessage = 'Timeout';
            break;
        }
        alert(errorMessage);
      };

      var options = {
        enableHighAccuracy: true,
        timeout: 1000,
        maximumAge: 0
      };

      navigator.geolocation.getCurrentPosition(successCallback,errorCallback,options);


I added &amp;language=en at the end of the script to display city name in english but it did not work it display the name in arabic any suggestion ?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1