I'm developing a site using opencart in which I plan to support multiple currencies. The currency should change based on the user’s physical location; that is, if a person opens it from the USA the currency visibility is set dollars, and if person in India opens it, it should be set to INR. Is that possible?
Asked
Active
Viewed 3,928 times
4
-
Are you looking for lat-long ? – Rayon Sep 22 '15 at 10:41
-
i want lat-long,by using that lat-long how can i chang the currency based on lat and long – venkat Sep 22 '15 at 11:00
-
You will find `apis` to do your job. Just by passing `lat-long`, you will get user location.. – Rayon Sep 22 '15 at 11:01
2 Answers
0
Try this:
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>

Rayon
- 36,219
- 4
- 49
- 76
-
1thanks bro, i got it and how the currency conversion will happen based on that geo location – venkat Sep 24 '15 at 07:07
-
You need to have a Databse where you can map **currencies** to **country name**, other option is to use `third-party-apis` to do this for you. You can accept this as an answer if it has helped you.. – Rayon Sep 24 '15 at 07:14
-
I would suggest you to this @ php end as that seems more robust solution. Better option is to use `ip-address` of the user as user my deny to provide his location. – Rayon Sep 24 '15 at 07:25
-
0
You can do this by using GeoLocation,Here is the code
$('.currency').text(geoplugin_currencyCode());
$('.symbol').html(geoplugin_currencySymbol());
<script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript">
</script>
<h6><span class="symbol"></span>90 <span class="currency"></span></h6>

Karan Goyal
- 447
- 5
- 10