android - Google Maps: custom LocationSource in iOS -


i have built android app able use google maps displaying users geo location several additional information beside wifi, cells , gps, instance qr codes, beacons or whatever use signal current position (i don't take account of actual accuracy of these locations). using locationsource , pass google maps api via setlocationsource.

i have use google maps apple maps limited in available zoom level, can't zoom buildings.

is possible provide custom locationmanager gets updated regularly action , inject google maps api locationsource?

i know there hacks place custom marker on map, makes impossible use other features of google maps move camera users location tapping on "my location" button.

thank you.

there solution. google maps api uses cocoa framework class cllocationmanager. how informed current gps location changes must conform cllocationmanagerdelegate , delegate of cllocationmanager object. updates being sent delegate object through locationmanager:didupdatelocations: delegate method. theory knows about. in order simulate location data need find way invoke method passing our own data it. fortunately there opportunity dynamically change behaviour of class, via functions class_addmethod , class_replacemethod. can change implementation of method abc method override_abc can implemented in category so:

let originalselector = nsselectorfromstring("setdelegate:") let newselector = nsselectorfromstring("override_setdelegate:")  let originalmethod = class_getinstancemethod(cllocationmanager.self, originalselector) let newmethod = class_getinstancemethod(cllocationmanager.self, newselector)  method_exchangeimplementations(originalmethod, newmethod) 

for our case, need change setter location managers delegate , add our own setter extension:

extension cllocationmanager {     func override_setdelegate(delegate: cllocationmanagerdelegate) {         // save reference self         gmlocationmanager = self         override_setdelegate(delegate)     } } 

once have saved reference google maps location manager can call locationmanager:didupdatelocations: delegate method using additional extension method simulatelocation.

extension cllocationmanager {     func simulatelocation(location: cllocation) {         self.delegate?.locationmanager?(self, didupdatelocations: [location])     } } // ...  gmlocationmanager?.simulatelocation(fakelocation) 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -