Native Reverse Geocoding

132 views
Skip to first unread message

Tim Gaul

unread,
Oct 21, 2014, 4:57:34 AM10/21/14
to codenameone...@googlegroups.com
Hi all

I can't make use of the reverse Geocoding API due to the quota limitations.

I've added a CN1lib library to do the reverse geocoding natively on iOS and Android. Android is working and tested!

However, the callback methods on iOS are throwing me off a bit:

#import "co_za_exafricanus_googlegeocoder_NativeGeocoderImpl.h"

@implementation co_za_exafricanus_googlegeocoder_NativeGeocoderImpl

-(NSString*)getAddressFromLocation:(double)param param1:(double)param1 param2:(int)param2{
   
NSMutableString *address;
   
   
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(param, param1) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {
       
       
for(GMSAddress* addressObj in [response results])
       
{
           
[address appendString: addressObj.thoroughfare];
           
[address appendString: @" "];
           
[address appendString: addressObj.subLocality];
           
[address appendString: @" "];
           
[address appendString: addressObj.locality];

           
break;
       
}
   
}];
   
   
return address;
}


-(BOOL)isSupported{
   
return YES;
}

@end

The logic is correct, however the completionHandler is asychronous and I'm unsure how to assign the values to address prior to returning the value?

Any suggestions?

Thanks!

Shai Almog

unread,
Oct 21, 2014, 8:19:15 AM10/21/14
to codenameone...@googlegroups.com
Hi,
I suggest updating the API so it supports asynchronous value return.
You can callback from C to Java using the tips covered here: http://www.codenameone.com/blog/native-ios-code-callbacks

Tim Gaul

unread,
Oct 21, 2014, 9:17:41 AM10/21/14
to codenameone...@googlegroups.com
Thanks Shai.

So if I understand correctly, I would call a static Java method from within my completionHandler (in the iOS native code) that would allow the value to be sent back from the native code. This static method could then perform the necessary updates to the application?

Tim

Tim Gaul

unread,
Oct 21, 2014, 10:39:57 AM10/21/14
to codenameone...@googlegroups.com
Hi Shai

I've tried your suggestion but am getting the following build error:

Undefined symbols for architecture armv7:
  "_co_za_exafricanus_googlegeocoder_Geocoder_updateAddress___int", referenced from:
      ___92-[co_za_exafricanus_googlegeocoder_NativeGeocoderImpl getAddressFromLocation:param1:param2:]_block_invoke in co_za_exafricanus_googlegeocoder_NativeGeocoderImpl.o
ld: symbol(s) not found for architecture armv7

Java Code:

package co.za.exafricanus.googlegeocoder;

import com.codename1.io.ConnectionRequest;
import com.codename1.io.NetworkManager;
import com.codename1.processing.Result;
import com.codename1.system.NativeLookup;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

public class Geocoder {
   
static String sAddress;
   
   
...

   
static void updateAddress(String result) {
       
Geocoder.sAddress = result;
   
}    
   
   
...
}

iOS native code:

#import <Foundation/Foundation.h>
#import "GoogleMaps.h"

@interface co_za_exafricanus_googlegeocoder_NativeGeocoderImpl : NSObject {
}

-(void)getAddressFromLocation:(double)param param1:(double)param1 param2:(int)param2;
-(BOOL)isSupported;
@end

#import <Foundation/Foundation.h>
#import "co_za_exafricanus_googlegeocoder_NativeGeocoderImpl.h"
#include "co_za_exafricanus_googlegeocoder_Geocoder.h"
#import "CodenameOne_GLViewController.h"

@implementation co_za_exafricanus_googlegeocoder_NativeGeocoderImpl

-(void) getAddressFromLocation:(double)param param1:(double)param1 param2:(int)param2{        
   
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(param, param1) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {
       
NSMutableString *address;

       
       
for(GMSAddress* addressObj in [response results])
       
{
           
[address appendString: addressObj.thoroughfare];
           
[address appendString: @" "];
           
[address appendString: addressObj.subLocality];
           
[address appendString: @" "];
           
[address appendString: addressObj.locality];

           
break;
       
}

       
        co_za_exafricanus_googlegeocoder_Geocoder_updateAddress___int
(CN1_THREAD_GET_STATE_PASS_ARG fromNSString(CN1_THREAD_GET_STATE_PASS_ARG address));
   
}];
}

-(BOOL)isSupported{
   
return YES;
}

@end



What am I doing wrong?

Thanks


Tim

On Tuesday, October 21, 2014 2:19:15 PM UTC+2, Shai Almog wrote:

Tim Gaul

unread,
Oct 22, 2014, 4:32:54 AM10/22/14
to codenameone...@googlegroups.com
Ok, I think there is a mistake in the example at http://www.codenameone.com/blog/native-ios-code-callbacks

public static void callback(String arg) translate to

com_mycompany_NativeCallback_callback___java_lang_String(CN1_THREAD_GET_STATE_PASS_ARG fromNSString(CN1_THREAD_GET_STATE_PASS_ARG nsStringValue));

and not

com_mycompany_NativeCallback_callback___int(CN1_THREAD_GET_STATE_PASS_ARG fromNSString(CN1_THREAD_GET_STATE_PASS_ARG nsStringValue));

Shai Almog

unread,
Oct 23, 2014, 12:19:03 AM10/23/14
to codenameone...@googlegroups.com
Yes, that's a mistake in our sample code. Thanks for the catch!

jack...@gmail.com

unread,
Oct 29, 2014, 6:16:12 AM10/29/14
to codenameone...@googlegroups.com
Hi all,

After correcting the code as mentioned, I still get the following error:


ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The method is called in this way:
com_mycompany_loadPath__java_lang_String(CN1_THREAD_GET_STATE_PASS_ARG fromNSString(CN1_THREAD_GET_STATE_PASS_ARG sPath));

Any suggestion?

Thanks

Diamond

unread,
Oct 29, 2014, 7:45:10 AM10/29/14
to codenameone...@googlegroups.com
Hi all,

I use Google Geocoding and ReverseGeocoding in my apps without Native Interface and it works perfectly on all platform, I even use Google Place AutoComplete which works perfectly too. 

If you will like to try my approach, send me an email on diamon...@gmail.com, I'm willing to share my codes and assist you in getting it to work perfectly  based on what you are trying to achieve.

Shai Almog

unread,
Oct 29, 2014, 9:46:29 AM10/29/14
to codenameone...@googlegroups.com, jack...@gmail.com
Hi,
can you provide the full error message from the linker?
Reply all
Reply to author
Forward
0 new messages