I have an Angular 12 Ionic app that is using the Google Maps API via #angular/google-maps package (https://github.com/angular/components/tree/master/src/google-maps#readme). The application we are building will be used in areas where internet access can be spotty at best. We are attempting to maintain functionality of the map when internet is lost. IE, potentially cache or store the loaded map locally to reference should we go offline.
We are expecting the user to be online when we initialize the map and load any polylines & markers
Should the user then go offline, and navigate around the app, when coming back to the map we would like to show the map, polylines and markers that were previously loaded.
What currently is happening is the the component is being destroyed and then reloaded when navigated back causing a reload of the map which cannot happen because we are offline. However, if we were able to cache or locally store that map, then we can load it from the cache/local until the user comes back online.
Using the package described above we are looking at trying to serialize the google.maps object to json for storage, however it is causing an issue.
let mapTest: google.maps.Map;
const center: google.maps.LatLngLiteral = { lat: centerPoint.lat, lng: centerPoint.lng };
mapTest = new google.maps.Map(document.getElementById('map') as HTMLElement, {
center,
zoom: 11
});
This is a basic typescript implementation as provided by the Google API Documentation (https://developers.google.com/maps/documentation/javascript/using-typescript). When we attempt to stringify the map we get the following error
Same error shows if we stringify mapTest.data.
Question is, is there anything we can do to locally store the google.map object or the google.map.data object? This ultimately will be put onto an Android device using Ionic, is something like this possible with Native Android maps? Or is this just not a feasible task at all
The Google Maps JavaScript API cannot be used offline.
See feature request: API feature to download a map for offline use.
Related
I am trying to use Google Maps for Android, offline (always and forever).
Surprisingly, I can't find any question here that asks or solves this issue specifically.
When I use a new offline phone, both my app and Google Maps show a blank map (dah, no map loaded) and 'my' location blue dot is not shown. Well, actually, no marker is shown.
To Reproduce
Restore any Android phone to its factory settings
Enable location services (GPS, without connecting to the internet at any stage)
Open the Google Maps app
--> See that there is no 'my location' blue marker, although when you long click on the screen, the app shows its coordinates (meaning, GPS does work, but the map doesn't show it)
Technical Symptoms
Even when I load offline maps (.mbtiles format, custom ones, not Google's) they're still not shown (nor the markers). It's like Google put some code like this:
if (no internet) hideAllViews().
Note that once I connect the phone to the internet, our custom tiles do work, even if I later turn the phone offline.
I can interact with the map (long click to view the clicked location, for example, which shows that my GPS location indeed works), but that's about it (until I connect the phone to the internet, from which point I can turn it offline again but with everything surprisingly working).
Code Example - a simplified version
//build.gradle:
implementation 'com.google.android.gms:play-services-maps:17.0.0'
//MapActivity.kt
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.MapView
import com.google.android.gms.maps.MapsInitializer
class MapActivity : AppCompatActivity {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.map_activity)
val mapFragment = supportFragmentManager.findFragmentByTag(MAP_FRAGMENT_TAG) as MapFragment?
?: MapFragment().also {
supportFragmentManager.beginTransaction().add(R.id.map, it, MAP_FRAGMENT_TAG).commit()
}
mapFragment.getMapAsync(::onMapReady)
mapFragment.retainInstance = true
}
private fun onMapReady(map: GoogleMap) {
map.isMyLocationEnabled = true
map.uiSettings.isMyLocationButtonEnabled = true
Log.d("GoogleMap", "Map should be ready and visible with my-location marker shown, if phone's GPS is enabled")
}
}
I hope someone here knows a trick or worked at Google and can shed some light on this.
Thank you!
As opposed to most similar questions, I do know how to make this work (internet...) but am asking specifically about a use case where a new phone can never be connected to the internet - not even one time for one second.
I am familiar with other offline maps services, but am trying to solve this with Google's maps, at least for now
It is not possible to load the API without connecting to the internet first since it was designed to be used online(As of now), so this is Working As Intended.
Please note that using Maps SDK for android requires an internet connection first to load because it checks the API key. Then you can use the Map offline for a certain period of time(there's no definite period of time for offline functionality that requires you to be online again)
But there are customers who are also interested in this functionality, so there is an ongoing entry for it in the Google Issue Tracker that was created since 2013 to let the API users be aware of this feature request.
You can view and star the feature request here:
https://issuetracker.google.com/35823181
Please note that the Issue Tracker entry above is the authoritative source for public information regarding the aforementioned feature requests, and all publicly-relevant updates will be posted there.
I have a weird behavior in my app. I have the google_maps_flutter plugin with the flutter_typeahead plugin which is used as an autocomplete address search.
When the user login in the app, the app only stores the user data in the internal database and the map is loaded, the app gets the current user location and set the map in such location, and then the user can use the autocomplete address search to type any address and load the results coming from Google Api Directions.
The strange thing here is, when I tap in the autocomplete, the page or the map is redrawn/reloaded and I can't do anything as you can see in this link:
App after just login.
But the most weird is, if I just exit from the app (no logout) with SystemNavigator.pop(animated: true);, and after that I open again the app, this behavior is gone and the app works, like this video: App reopened.
I don't have a clue why, and I can't post the code here, first, because it's a production app and second, because the minimal code is so extense to publish it here.
It's a little similar to my Github issue: https://github.com/flutter/flutter/issues/78638 but here, although I'm getting in realtime the user location, the map isn't moving because I'm in the same place al the time.
EDIT: In the dispose method for the StatefulWidget I set a debug print to check when this is disposed and when I tap on the typeahead plugin, I see the StatefulWidget (where is the map and the typeahead) is disposed, when I just login, but it isn't present when I reopen the app.
I'm using Maps Android API in the offline mode extensively in travel apps I build. On the first app launch, I download all the tiles I need so that they're available later in the field without the Internet. Everything works great, but I noticed that the Maps API does require Internet connection on its first use after app installation. The framework probably performs API key validation to make sure it's legit.
Since my fragments containing com.google.android.gms.maps.MapView are not displayed on the first screen, there's a risk a user downloads the map for offline use in a hotel, goes into the wild, and... kaboom! - map is not displayed.
How to initialize Android Map framework so that maps are available later when there's no connection? Is there a way to skip online key validation?
After some experimenting I found out a simple solution.
So, first, in my first activity layout (it's a host activity for all my fragments) I added the following zero-sized invisible MapView:
<com.google.android.gms.maps.MapView
android:id="#+id/dummyMapViewToInitForOfflineUse"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="invisible"
/>
Then, in the activity code, I added the following method:
private void initGoogleMapFrameworkToMakeItUsableOfflineLater() {
dummyMapViewToInitForOfflineUse.onCreate(new Bundle());
dummyMapViewToInitForOfflineUse.getMapAsync(ignored -> {
Timber.d("GoogleMap framework initialized and ready to use offline later");
});
}
You can call it in onCreate as well as at any other reasonable moment (I use AndroidAnnotations, so I called it from my init method annotated with #AfterViews). Obvoiusly, if you don't use AndroidAnnotations or other view binding framework, you need to perform findViewById(R.id.dummyMapViewToInitForOfflineUse).
If you are aiming at caching google map's tiles for offline use then you may be violating their terms,You are first required to purchase their enterprise Maps API Premier, check this link How to cache Google map tiles for offline usage?
I am using the mapQuest Android SDK for developing a Navigation app. Whenever I try to create a route with the Route Manager, I get the following error
Status Code: 403[This key is not authorized for this service. If you do not have a key, you can obtain a free key by registering at http://developer.mapquest.com.]
This occurred all of a sudden and since last week I have not been able to form a route
The app key is open and free edition and it starts with F
Creating a new app key does not solve the problem either
It seems the best approach for now is to use your key to hit the Directions API webservice, then parse the result into a line overlay that can be shown on your map, html for a narrative webview, or both.
This thread from the Mapquest developers forum is a good starting point:
http://developer.mapquest.com/web/products/forums/-/message_boards/message/1522959
What I have: native android app that use Android Maps API v2 (native library)
Everything works good in Hong Kong and Ukraine. The problems came as soon as we step in China border. We have next problems:
Map is loading from 30 mins to about one hour.
Even when it's loaded, the map resolution is very low http://i.gyazo.com/d4f40e1a225bd48a90087c39a502e4a6.png
Google Map WORKS by itself: http://i.gyazo.com/dc85e3618c285ced5bba799053dd0306.png
What I know around China:
Google is not really friendly there, but our app is not the one that is used a google maps in China, so my problem probably is not a new one.
There is the option to use a google maps hosted locally in China - ditu.google.cn, but as soon as we are using the native app there is not an option now to use a web view of map instead of native implementation (we have a lot of customizations)
I know, that better do not use HTTPS with Google maps (you can read around this here: Google Maps Geolocation API for China)
The question is:
Could we somehow improve the load of map? Could we somehow override the google map source to use a ditu.google.cn?
Could we somehow disable HTTPS in Map API?
Any other solution around this problem, that can be applied based on google services. Maybe there is some undocumented features?
What is did not expect as an answer is something like "Use Baidu". I know Baidu and this is a veeerryyy backup option as soon as they have an api docs in chineese.
It's fare to add, that Geocoding API based on ditu.google.cn works good.
Looking forward, thank you!
Maybe you can't override the original tile source. But you can use TileOverlay to get maps tile from external server.
Usage example :
TileProvider tileProvider = new UrlTileProvider(256, 256) {
//...
#Override
public URL getTileUrl(int x, int y, int zoom) {
/* Define the URL pattern for the tile images */
String s = String.format("http://my.image.server/images/%d/%d/%d.png",
zoom, x, y);
if (!checkTileExists(x, y, zoom)) {
return null;
}
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
//...
}
You can replace the my.image.server with ditu.google.cn and use external server API to get tile images. In the Maps, you can set OnCameraChangeListener, so the application will load tiles from external server when the map is zooming or panning.
Read more : https://developers.google.com/maps/documentation/android/tileoverlay
Google still has no map publishing license in China (at least as my latest info goes) It may well be that in the near future Google's Map services will be blocked.
A lot of Chinese websites, including ours, use Google's JS as well as their Service API's, Among them is Google's geocoding api. in china, baidu (NASDAQ:BIDU) and sogou [the minor search engine, part of sohu (NASDAQ:SOHU)] both provided online maps and also APIs,
baidu’s map api home is http://dev.baidu.com/wiki/map/in...
sogou’s map api home is http://map.sogou.com/api/
actually, in china, as of now, the google maps api are still available now. as from recent chinatech.us news, Google China passed the annual inspection and got more opportunity to get online map business license so, the 3 API are are and available.