Comments (21)
How about .then()
instead of .subscribe()
?
from ionic-googlemaps-demo.
Not allowed for Observable. But changing the type to Promise will allow that function and is probably the fix
from ionic-googlemaps-demo.
Morning
from ionic-googlemaps-demo.
I finally came back to this project. I'm trying to catch up this issue, just a moment please.
from ionic-googlemaps-demo.
I checked the @ionic-native/src/plugins/google-maps/index.ts
-
then
is for one time event.map.addMarker({...}).then(() => {});
-
subscribe
is for the event more than one time (it meansaddEventListener
)map.on(GoogleMapsEvent.CAMERA_CHANGE).subscribe(()=>{});
BaseArrayClass fires insert_at
, set_at
and remove_at
events more than one time,
the code should use subscribe
.
let baseArrayClass = new BaseArrayClass();
baseArrayClass.on('insert_at').subscribe(() => {
});
from ionic-googlemaps-demo.
Marker is working fine and as expected
var markers = new BaseArrayClass([]);
markers.on('insert_at').subscribe(() => {
});
note that BaseArrayClass does not have a default constructor in the Ionic wrapper
The problem is this one
self.geocoder.geocode({
// US Capital cities
"address": [
"Montgomery, AL, USA", "Juneau, AK, USA", "Phoenix, AZ, USA",
....
"Providence, RI, USA", "Columbia, SC, USA", "Pierre, SD, USA",
"Nashville, TN, USA", "Austin, TX, USA", "Salt Lake City, UT, USA",
"Montpelier, VT, USA", "Richmond, VA, USA", "Olympia, WA, USA",
"Charleston, WV, USA", "Madison, WI, USA", "Cheyenne, Wyoming, USA"
]
}).then((mvcArray: BaseArrayClass<GeocoderResult>) => {
// Init some other stuff
mvcArray.on('insert_at').subscribe((index) => {
});
When the statement is executed I get the error
Cannot read property 'subscribe' of undefined
I added a breakpoint in BaseClass.js
self.on = function(eventName, callback) {
if (!eventName || !callback || typeof callback !== "function") {
return;
}
and on this call callback is undefined
Looking at javascript console it looks like this
Pressing F11 (single step) results in this:
from ionic-googlemaps-demo.
note that BaseArrayClass does not have a default constructor in the Ionic wrapper
It seems BaseArrayClass of the ionic wrapper has default constructor.
https://github.com/wf9a5m75/ionic-native/blob/57179a125b66afbcb5ea0c5f6aa27be6d1423a6c/src/%40ionic-native/plugins/google-maps/index.ts#L557-L565
from ionic-googlemaps-demo.
I found the reason.
The BaseArrayClass of ionic wrapper extends IonicNativePlugin
export class BaseArrayClass<T> extends IonicNativePlugin {
But the original BaseArrayClass extends BaseClass
utils.extend(BaseArrayClass, BaseClass);
That's the reason.
from ionic-googlemaps-demo.
Hence, the BaseArrayClass should be like this:
export class BaseArrayClass<T> extends BaseClass {
from ionic-googlemaps-demo.
Ok, I will update that
from ionic-googlemaps-demo.
Thank you :)
from ionic-googlemaps-demo.
I have changed that but still have the same problem with the subscribe.
But I did look in Geocode.js where the mvcArray is created
if (geocoderRequest[requestProperty] instanceof Array ||
Array.isArray(geocoderRequest[requestProperty])) {
//-------------------------
// Geocoder.geocode({
// address: [
// "Kyoto, Japan",
// "Tokyo, Japan"
// ]
// })
//-------------------------
requestCnt = geocoderRequest[requestProperty].length;
mvcResults = common.createMvcArray();
for (i = 0; i < requestCnt; i++) {
mvcResults.push(-1, true);
}
the createMvcArray() looks like this
function createMvcArray(array) {
var mvcArray;
if (array && typeof array.getArray === "function") {
mvcArray = new BaseArrayClass(array.getArray());
array.on('set_at', function(index) {
var value = array.getAt(index);
value = "position" in value ? value.getPosition() : value;
mvcArray.setAt(index, value);
});
array.on('insert_at', function(index) {
var value = array.getAt(index);
value = "position" in value ? value.getPosition() : value;
mvcArray.insertAt(index, value);
});
array.on('remove_at', function(index) {
mvcArray.removeAt(index);
});
} else {
mvcArray = new BaseArrayClass(!!array ? array.slice(0) : undefined);
}
return mvcArray;
So the BaseArrayClass is instantiated with an undefined type, could that be the issue - And I am just guessing, haven't still figured all the aspects of the mapping out :-)
from ionic-googlemaps-demo.
Um, I will catch up you. Just a moment please.
from ionic-googlemaps-demo.
@ThorvaldAagaard I fixed the BaseArrayClass definition. Please git pull
, npm run build google-maps
, then reinstall npm uninstall @ionic-native/google-maps; npm install (path to)/ionic-native/dist/\@ionic-native/google-maps
https://github.com/wf9a5m75/ionic-native/commit/2c7e686d121f5b6054ed597051c2aba86aaf3ab4
from ionic-googlemaps-demo.
Great, I will test the change, it almost the same as the one I made, but I can see you are instantiating the property a different way then I did
this._objectInstance = GoogleMaps.getPlugin().BaseArrayClass(initialData);
I will get back with the result in a moment
from ionic-googlemaps-demo.
Hmm,
mvcArray.on('insert_at').subscribe((index) => {
});
still executes the on() method on BaseClass directly with an undefined callback
but
var markers = new BaseArrayClass([]);
markers.on('insert_at').subscribe(() => {
});
executes this method
Both are of type BaseArrayClass
but it is like the working one has an outer level
_objectInstance
This is only executed for the working one
function BaseArrayClass(initialData) {
var _this = _super.call(this) || this;
_this._objectInstance = GoogleMaps.getPlugin().BaseArrayClass(initialData);
return _this;
}
whereas the mvcArray is instantiated directly.
I can see in Common.js the reference to BaseArrayClass is the one in BaseArrayClass.js and not the definition in the Ionic-wrapper.
But I have no idea about how to fix that
from ionic-googlemaps-demo.
Sorry, I finally came back. I will check this deeply from now.
from ionic-googlemaps-demo.
No problem. I am learning, but its bedtime here now
from ionic-googlemaps-demo.
Yap. Please have a good sleep. I'm also still learning. I will update.
from ionic-googlemaps-demo.
@ThorvaldAagaard I fixed the bug of BaseArrayClass and Geocoder.geocode.
And I also created the page of Geocoder/geocoding.
Please git pull
both @ionic-native repository and this repository.
from ionic-googlemaps-demo.
Working fine, thus there seems to be a minor error but I will close this and create a new issue
from ionic-googlemaps-demo.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ionic-googlemaps-demo.