Transform Current Geolocation to Desired Geolocation

In many iPhone application development projects that I have done, I had to work on Geo-fencing feature i.e. It should prompt an alert to user (“You are nearby X place”) when user is passing through any location within certain radius.

So when I was developing such iOS applications, it was practical and assumed that I cannot go to all places and test the application, so for such kind of testing with live records I have used below function to change/transfer user’s geo-location to any particular area.

For this you have to take arbitrarily any location and use your current location to find out offset values and get it done as explained below. To transform any location to any other area on geographical plan you need to apply offset values on the current latitude and longitude of user location.

Kindly follow below steps to transform any points to other plan. It is explained using one of the iOS features related to “Settings” bundle. Because that way you can change offset very quickly without doing statically within an application.

How to create setting bundle with Offset points ?

Add setting bundle into your application:

Add two text field and set their values as shown in below image.

In a common method class or in application delegate file you will have to write down below two methods. One method is responsible to apply offset value on latitude for current location and another is for longitude.

Method-1:

Objective-C

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

// Method that fetches latitude offset value from the setting and apply on the latitude.

-(double)applyLatitudeOffset:(double)latitude{

doublelatitudeOffset=0.0;

NSUserDefaults*defaults=[NSUserDefaultsstandardUserDefaults];

if([defaults objectForKey:@"LatOffset"]==nil){

returnlatitude;

}

if([[defaults objectForKey:@"LatOffset"] length]==0){

returnlatitude;

}

latitudeOffset=[[defaults objectForKey:@"LatOffset"] doubleValue];

doublenewLatitude;

newLatitude=latitude+latitudeOffset;

returnnewLatitude;

}

Method-2:

Objective-C

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

// Method that fetches longitude offset value from the setting and apply on the longitude value.

-(double)applyLongitudeOffset:(double)longitude{

doublelongitudeOffset=0.0;

NSUserDefaults*defaults=[NSUserDefaultsstandardUserDefaults];

if([defaults objectForKey:@"LongOffset"]==nil){

returnlongitude;

}

if([[defaults objectForKey:@"LongOffset"] length]==0){

returnlongitude;

}

longitudeOffset=[[defaults objectForKey:@"LongOffset"] doubleValue];

doublenewLongitude;

newLongitude=longitude+longitudeOffset;

returnnewLongitude;

}

How to calculate Offset Values to set under “Settings” ?
You need to have your current location and desire location where you would like to move your current position. Below examples shows how you can calculate offset value.

iOS Team @ Weblineindia

We are iOS Team @ Weblineindia.

We are energetic, adaptive and enthusiastic to explore our limits in this dynamic world of Mobile App Development. We always remains up-to-date with industry standards and trends that are followed for mobile application development. We have so far delivered applications in various domains like Business, Health & Fitness, Social Networking, Utilities and many more. We have also delivered many enterprise applications and complex architecture applications which follows SAAS model.

We have expertise in developing iPhone / iPad Applications, Universal Apps, iWatch Applications and Mac OS Applications which includes many rich features like offline data storage using core data / sqlite framework, cloud based APIs, usage of widgets and extensions, push notifications, in-app purchase functionality, siri enabled features and many more.

As a team, we are always eager to contribute back to the community and so happy to help here to our developer community on any technical problems and discussions.