I am using the native Google Maps plugin in ionic and I am encountering a strange situation. Basically, I followed the example from the Ionic site. So when I start the app on androidn using ionic cordova run android this work fine. However, if I add --livereload, the map refuses the load. Actually, GoogleMaps.create() method returns an empty object {}. Anyone encountered this?
I am assuming that --livereload has a backend web server running that reloads the app which might cause the native plugin to fail?
Any insights?
For the livereload, insert setTimeout() before GoogleMaps.create().
Because when the app executed GoogleMaps.create(), platform.ready() is not ready.
loadMap() {
setTimeout(() => {
this.map = GoogleMaps.create('map_canvas');
}, 1000);
}
Related
I have just migrate my application from ionic v2.0.0 to v3.0.1 and I have a issue with the ionic native Google maps plugin.
Almost everything is working except the following code:
if (this.destination != null) {
plugin.google.maps.external.launchNavigation({
"from": this.currentLocation,
"to": this.destination
});
Do you know how to update this piece of code to make it work with Ionic v3.0.1 ?
Thanks.
Regards.
Im using google analytics in my app. I want to start tracking on platform ready. But the code consoled in to catch function. My code is
GoogleAnalytics.startTrackerWithId('UA-xxxxxxxx-1'); //replaced id
.then(function() {
console.log('Google analytics is ready now');
}).catch(function(e) {
console.log('Error starting GoogleAnalytics', e);
});
My output is Error starting GoogleAnalytics Tracker not started. How to solve this? Thanks in advance..
Make sure you're using the latest ionic the problem was in an old ionic native version where the parameters had a problem, have a look here:
https://github.com/danwilson/google-analytics-plugin/issues/291
I've got the same issue, after updating all plugins inside the platform.json the tracking is working without any problems.
Make sure its in Platform ready, And it will only work on a device.
import { GoogleAnalytics } from 'ionic-native';
import { Platform } from 'ionic-angular';
constructor(public plt: Platform) {
this.plt.ready().then((readySource) => {
GoogleAnalytics.startTrackerWithId('YOUR_TRACKER_ID')
.then(() => {
console.log('Google analytics is ready now');
// Tracker is ready
// You can now track pages or set additional information such as AppVersion or UserId
})
.catch(e => console.log('Error starting GoogleAnalytics', e));
});
}
Is a problem related with google-play-services incompatibilities. For fix it you have to make sure that all the PLAY_SERVICES_VERSION are the same, in my case for google-maps, googleplus and the rest I used 15.0.2, but for analytics I have to use 15.0.2 (because there are not a 15.0.1 in maven repo).
SO go to your config.xml and add/change your analytics plugin tag to
<plugin name="cordova-plugin-google-analytics">
<variable name="PLAY_SERVICES_VERSION" value="15.0.2" />
</plugin>
and make sure that all the other plugins have some 15.* version. (if you are using another one just make sure that all play service use the same version)
Then if you already added a platform, go to platforms/android/project.properties and the same, just make sure that all play-services libraries are the same version. for example I have:
cordova.system.library.10=com.google.android.gms:play-services-analytics:15.0.2
cordova.system.library.13=com.google.android.gms:play-services-maps:15.0.1
...
Hope that this work for you, work for me after a lot of research.
I have created in windows phone in Cordova. All things are working fine.
But now I have integrated Push Notification using Parse. I have configured correctly. But now I am only getting push when my app is in background or closed. But I am not getting Push notification when my app is open.
I have used this plugin.
Finally found the answer.
I have remove old plugin and install https://github.com/cookys/parse-push-plugin
and add below code in App.xaml.cs file
// Parse initialization
ParseClient.Initialize("APP_ID", ".NET_KEY");
this.Startup += async (sender, args) =>
{
ParseAnalytics.TrackAppOpens(RootFrame);
await ParseInstallation.CurrentInstallation.SaveAsync();
};
It worked for me. :)
I'm currently using the Async plugin to load Google Maps in our application using RequireJS (https://github.com/millermedeiros/requirejs-plugins):
define("googleMap", ['async!https://maps.googlee.com/maps/api/js?v=3&sensor=false']);
Then include it wherever I need it:
define(['googleMap'], function () { ... });
From China for example, Google Maps is forbidden and it will result with a "Load timeout for modules: async!googleMap". This will also break the entire website as the dependency is not available.
How can I catch that error so the app can run? Then wherever I use googleMap I would check that the object 'google' exists before using it.
I think you can ping the site before you pull your js, just like this answer does:
Is it possible to ping a server from Javascript?
I have a dynamic website. It uses mysql database which is provided by the hosting team. I need my android app to use the same database. How could I integrate the same.?
An Ajax request in Cordova/Phonegap is the same as using the standard jQuery:
For retrieving data I used in my app [minimalist code]:
$.getJSON(url).done(function (jsonData) {
console.debug('retrieved JSON');
// process your data here
}).fail(function () {
console.debug('cannot retrieve remote URL');
// error occurred
});
See also here: Calling a REST service from a Cordova application using jQuery and othere questions here in SO such as: How to call SOAP service from Phonegap (iPhone app).