In react native i am trying to get user country without using the users gps, just like Wechat registration which automatically gets the users country in the picker(select) field.
it can be done by two ways
get the IP address of user but it works only with internet connection
the best way is to get the local country of the device itself with the use of
react-native-device-info
const deviceCountry = DeviceInfo.getDeviceCountry(); // "US", "IN"
ref: react-native-device-info#getdevicecountry
getDeviceCountry() is removed from react-native-device-info.
Use react-native-localize:
import * as RNLocalize from "react-native-localize";
RNLocalize.getCountry(); // -> 'UA'
If you want to get a full country name like "United States" then you can add following json file to your project: https://gist.github.com/ssskip/5a94bfcd2835bf1dea52
And then import and get full country name by code:
const countries = require('./countries.json')
// Or in ES6:
// import countries from './countries.json'
countries[RNLocalize.getCountry()] // -> 'United States'
Related
Hello to all the community,
Thank you in advance to whoever will take the time to answer me 😆!
In fact, I want to find a solution to make the minimum purchase on the checkout page ( not on the cart page ) and it depends on the address city.
I already did it in Prestashop 1.6 but now I use Prestashop 1.7.7.1 I am obliged to override the cart Presenter but I didn't rich a convenient solution.
Even I purchased a module of minimum purchase by country and modified it to be by the city but the module itself is not stable and it didn't work properly and the support of the module cannot find a solution because it requires an override of the core of Prestashop in the Symfony code and it will affect all the order tunnel which is typically impossible.
This topic will be a real challenge for developers that they don't know the impossible 😆!
Thanks in advance.
Assuming you are creating a module, in CartPresenter class you have hook overrideMinimalPurchasePrice. You can hook your module to this hook and modify the $minimalPurchase value in your module according to your logic.
You said that price depends on the address's city. Well, in your hook you can get the address, because in Prestashop front-office you always have access to cart and cart might have delivery address id:
public function hookOverrideMinimalPurchasePrice($params)
{
$cart = $this->context->cart;
$id_address = $cart->id_address_delivery;
// If customer did not enter the address yet, the address id is 0.
if($id_address != 0)
{
$address = new Address($id_address);
$city = $address->city;
if($city == 'New York')
$params['minimalPurchase'] = 100;
}
}
}
You do not have to return anything in the hook, because in CartPresenter.php the hook is called with parameter being passed by reference:
Hook::exec('overrideMinimalPurchasePrice', [
'minimalPurchase' => &$minimalPurchase,
]);
I am looking to create subcollections with React Native Firebase to create a firestore structure like this:
groups
->group
->scheduledQuestionnaires
->questionnaire (fields: id, type and timestamp)
users
->user
->groups
(fields: id and name)
I have created the collections groups and users, but how can I create a subcollection scheduledQuestionnaires for every group programmatically.
I am able to add documents with fields to collections just fine, but I can't seem to find a way to create (sub)collections. Am I going the wrong way about it or am I missing something?
EDIT
To add to the answer by monsty. Here is a code snippet of what I wanted to do:
firestore()
.collection('groups')
.doc('group1/scheduledQuestionnaires/questionnaire1')
.set({
id: '1',
type: 'type',
timestamp: 'timestamp',
});
You don't need to create subcollections for every collection, because Firebase will handle it.
If you try to save a document into "/groups/group/scheduledQuestionnaires/hello/world/my_document", Firebase will create all the sub collections needed (in this case : hello and world).
Im using google geocoder and I want to restrict result to some countries (for example I don't want to search in USA).
Using:
componentRestrictions: {
country: 'de'
}
Works fine, but I would like to add more countries, tried passing array:
componentRestrictions: {
country: ['de','at','ch']
}
But it gives an error
Is there anyway to add more than one country to restrictions?
Thanks
Is there any way of getting a list of all artists who are presented on Soundcloud ( via it`s API or by some other means) ?
Here is a bit of code which should point you in the right direction.
Problem could be the response limit, which is 200.
That's why you have to store the responses anywhere to get a full list of all artists (users) on SC.
To get a list of users you can do the following by using the SC JS SDK.
May be you can play around with the q parameter.
JS Code:
SC.initialize({ client_id: "201b55a1a16e7c0a122d112590b32e4a"});
SC.get('/users', { limit: 200}, function(users) { console.log(users);});
Example here:
http://jsfiddle.net/iambnz/9kUwq/
Docs:
http://developers.soundcloud.com/docs/api/guide#search
http://developers.soundcloud.com/docs/api/reference#users
few month ago i write something to get the latitude or longitude from google API. latter i get the database from drupal for latitude or longitude to most of city in worlds.
but the problem is that the same city name can be found two or more times in a area. like Firozabad in India and bangladesh both. Agra in UP and agar in Rajasthan.
means the confusion in name by user if they found two city by same name they are confused.
i hear that HTML 5 support latitude or longitude of the visiter but i need latitude or longitude where they are born or city they want to use to fill a form.
how i can get the latitude or longtiude from API like google and some other.
the process is that:
user put the location in textbox for getting their latitude or longitude.
for right thing i want to show them all location [if same thing found more then one].
they can choose the right location and after click they can get the lati and langitude.
how i can do this using any API.
If I understood you correctly then here's a Javascript function that returns a list of actual locations based on the address (full or partial) that user has entered:
getLocationsByAddress = function(address, onComplete) {
var geocoder = null;
var locations = [];
var location = null;
geocoder = new GClientGeocoder();
geocoder.getLocations(address, function(response) {
if (!response || response.Status.code != 200) {
if (typeof (onComplete) != 'undefined') {
onComplete([]);
}
} else {
for (var i = 0; i < response.Placemark.length; i++) {
location = response.Placemark[i];
locations[locations.length] = {
address: location.address,
x: location.Point.coordinates[1],
y: location.Point.coordinates[0],
zoom: 14
}
}
if (typeof (onComplete) != 'undefined') {
onComplete(locations);
}
}
});
}
The code uses API version 2 but I think it should be fairly easy to make it work with V3 (please see this API reference for details).
UPDATE
As #Maxym stated the V2 API is considered as deprecated and therefore shouldn't be used any further.
Take a look at this jQuery plugin. It claims to work with both V2 and V3 so you may want to examine the source code in order to find out how they do an it with V3.
I am not sure that it is about HTML 5. You just need to create sort of hints, where user can select which exactly city she means (the way Google does on maps.google.com - you enter "Odessa" and see list of cities with such name). Google has geocoder API but probably it should be used with Google Map (just read license).
So the process is easy: user enters city, you send it to geocoder to get list of cities with such a name and their coordinates. THen you show that list, user selects one and you have its coordinates.
There is documentation how to use Geocoding API v3 in JavaScript, as well as examples. This one show how to get coordinates from address, take into account that they process results[0] only, but you need to iterate over results to get all cities.