Skip to content

Commit

Permalink
feat: added setLocation function (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
AjilJagadeesh7 authored Mar 12, 2024
1 parent db8e980 commit 970be9b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions android/src/main/java/com/mparticle/react/MParticleModule.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mparticle.react;

import android.location.Location;
import android.util.Log;

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

@ReactMethod
public void setLocation(double latitude, double longitude) {
Location newLocation = new Location("");
newLocation.setLatitude(latitude);
newLocation.setLongitude(longitude);
MParticle.getInstance().setLocation(newLocation);

}

@ReactMethod
public void logEvent(final String name, int type, final ReadableMap attributesMap) {
Map<String, String> attributes = ConvertStringMap(attributesMap);
Expand Down
6 changes: 6 additions & 0 deletions ios/RNMParticle/RNMParticle.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ + (void)load {
[[MParticle sharedInstance] upload];
}

RCT_EXPORT_METHOD(setLocation:(double)latitude longitude:(double)longitude)
{
CLLocation *newLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
[MParticle sharedInstance].location = newLocation;
}

RCT_EXPORT_METHOD(setUploadInterval:(NSInteger)uploadInterval)
{
[[MParticle sharedInstance] setUploadInterval:uploadInterval];
Expand Down
7 changes: 6 additions & 1 deletion js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ const getSession = (completion) => {
NativeModules.MParticle.getSession(completion)
}

const setLocation = (latitude, longitude) => {
NativeModules.MParticle.setLocation(latitude, longitude)
}

// ******** Identity ********
class User {
constructor (userId) {
Expand Down Expand Up @@ -686,7 +690,8 @@ const MParticle = {
isKitActive,
getAttributions,
logPushRegistration,
getSession
getSession,
setLocation
}

export default MParticle

0 comments on commit 970be9b

Please sign in to comment.