Skip to content

Commit 970be9b

Browse files
feat: added setLocation function (#196)
1 parent db8e980 commit 970be9b

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

android/src/main/java/com/mparticle/react/MParticleModule.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mparticle.react;
22

3+
import android.location.Location;
34
import android.util.Log;
45

56
import com.facebook.react.bridge.Arguments;
@@ -73,6 +74,15 @@ public void setUploadInterval(int uploadInterval) {
7374
MParticle.getInstance().setUpdateInterval(uploadInterval);
7475
}
7576

77+
@ReactMethod
78+
public void setLocation(double latitude, double longitude) {
79+
Location newLocation = new Location("");
80+
newLocation.setLatitude(latitude);
81+
newLocation.setLongitude(longitude);
82+
MParticle.getInstance().setLocation(newLocation);
83+
84+
}
85+
7686
@ReactMethod
7787
public void logEvent(final String name, int type, final ReadableMap attributesMap) {
7888
Map<String, String> attributes = ConvertStringMap(attributesMap);

ios/RNMParticle/RNMParticle.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ + (void)load {
3030
[[MParticle sharedInstance] upload];
3131
}
3232

33+
RCT_EXPORT_METHOD(setLocation:(double)latitude longitude:(double)longitude)
34+
{
35+
CLLocation *newLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
36+
[MParticle sharedInstance].location = newLocation;
37+
}
38+
3339
RCT_EXPORT_METHOD(setUploadInterval:(NSInteger)uploadInterval)
3440
{
3541
[[MParticle sharedInstance] setUploadInterval:uploadInterval];

js/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ const getSession = (completion) => {
158158
NativeModules.MParticle.getSession(completion)
159159
}
160160

161+
const setLocation = (latitude, longitude) => {
162+
NativeModules.MParticle.setLocation(latitude, longitude)
163+
}
164+
161165
// ******** Identity ********
162166
class User {
163167
constructor (userId) {
@@ -686,7 +690,8 @@ const MParticle = {
686690
isKitActive,
687691
getAttributions,
688692
logPushRegistration,
689-
getSession
693+
getSession,
694+
setLocation
690695
}
691696

692697
export default MParticle

0 commit comments

Comments
 (0)