2015-09-22 69 views
0

我正在开发一个使用opencart的网站,我计划支持多种货币。货币应该根据用户的实际位置而改变;也就是说,如果一个人从美国开户,货币可见性就是美元,而如果印度的人打开它,则应该设置为INR。那可能吗?使用地理定位更改货币

+0

您是否在寻找LAT-长时间? – Rayon

+0

我想通过使用经纬度长度的经纬度,如何根据纬度和经度来改变货币 – venkat

+0

您会发现'apis'来完成您的工作。只要通过'lat-long',您就可以获得用户位置。 – Rayon

回答

0

试试这个:

function getLocation() { 
    if (navigator.geolocation) { 
    navigator.geolocation.getCurrentPosition(showPosition); 
    } else { 
    console.log("Geolocation is not supported by this browser."); 
    } 
} 

function showPosition(position) { 
    GetAddress(position.coords.latitude, position.coords.longitude) 
} 

function GetAddress(lat, lng) { 
    var latlng = new google.maps.LatLng(lat, lng); 
    var geocoder = geocoder = new google.maps.Geocoder(); 
    geocoder.geocode({ 
    'latLng': latlng 
    }, function(results, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
     if (results[0]) { 
     var address = results[1].address_components; 
     for (var i = 0, iLen = address.length; i < iLen; i++) { 
      if (address[i].types[0] === 'country') { 
      var countryName = address[i].long_name; 
      alert(countryName); 
      } 
     } 
     } 
    } 
    }); 
} 
<button type="button" onclick="getLocation()">Get Location</button> 
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 

Plunker here

+0

感谢兄弟,我明白了,以及如何根据该地理位置进行货币转换 – venkat

+0

您需要有一个Databse,您可以在其中映射**货币* *到**国家名称**,其他选项是使用'第三方-APIS'为你做这个。你可以接受这个答案,如果它对你有帮助的话。 – Rayon

+0

我建议你这个@ php结束,因为这似乎更强大的解决方案。更好的选择是使用用户的ip地址作为用户拒绝提供他的位置。 – Rayon