Load Google Maps With Directions From Chrome Mobile for Android - android

I am working on a program that lists directions for errand runners so they know where to drive. It delivers the results on their phone. Every errand runner will be using a Galaxy Samsung Tab 3 with Google Chrome browser. So it is using the mobile version of Google Chrome.
Is it possible to launch Google Maps from a link on a webpage with directions to a clients address and get it started navigating to them?
I did some research into this https://developers.google.com/chrome/mobile/docs/intents and it looks like it might be possible but I'm not sure how to do it or if it will work like I intend?
I also found this (http://developer.android.com/guide/appendix/g-app-intents.html), might help give clues to the answer.

I recently found a solution. Apparently just linking to google maps on the device will prompt if you want to open with the maps program, which will work for my purposes.
To make it work properly you will want to link to Google Maps using Coordinates.
In javascript my function looks like below
JS:
function getPosition(position){
latitude = position.coords.latitude;
longitude = position.coords.longitude;
var url = 'http://maps.google.com/maps?saddr='+latitude+','+longitude+'&daddr='+navAddress;
window.location.href = url;
}
$("body").on("click",".routemap",function(){
navAddress = $(this).attr("address");
navigator.geolocation.getCurrentPosition(getPosition);//get the current position for google maps linking purposes.
});

Related

Google maps cross-platform URL fails to load route on Android after "in app navigation"

I have an Angular 9 + Ionic 5 application, deployed as PWA, Android and IOS apps.
We use google's universal, cross-platform URL to launch Google Maps,
as described here: https://developers.google.com/maps/documentation/urls/get-started
Function open a location in google maps:
export const openMaps = (lat: number, lng: number) => {
const url = `https://www.google.com/maps/search/?api=1&query=${lat}%2C${lng}`;
return window.open(url, '_top').focus();
};
This works fine in PWA and IOS app, however in Android after the address is loaded in browser as expected, it fails to launch Navigation after supporting start location in Route planner and tapping on "IN APP NAVIGATION". (Same happens if i provide the link with Directions to start navigation automaticly).
Error shown after tapping "IN APP NAVIGATION":
The webpage at intent://maps.app.goo.gl/?link=https://www.google.com/maps/dir//50.253722,10.958954/#49.9145812,10.9626145,8z/data%3D!4m2!4m1!3e0!11m1!6b1?entry%3Dml&apn=com.google.android.apps.maps&amv=914018424&isi=585027354&ibi=com.google.Maps&ius=comgooglemapsurl&utm_campaign=ml_promo&ct=ml-nav-nopromo-dr-nlu-wv-msc&mt=8&pt=9008&efr=1#Intent;package=com.google.android.gms;scheme=https;S.browser_fallback_url=https://play.google.com/store/apps/details%3Fid%3Dcom.google.android.apps.maps&pcampaignid%3Dfdl_long&url%3Dhttps://www.google.com/maps/dir//50.253722,10.958954/#49.9145812,10.9626145,8z/data%253D!4m2!4m1!3e0!11m1!6b1%3Fentry%253Dml&min_version%3D914018424;end; could not be loaded because:
net::ERR_UNKNOWN_URL_SCHEME
Does someone have an idea what went wrong here? The URL syntax should be correct, but seems like the google maps intent loads an unknown scheme on Android.
Solved! Problem was window.open(url, '_top').focus();
These link should be used with target: _system.
And in case of hybrid Ionic app, the following plugin is also recommended!
https://ionicframework.com/docs/native/in-app-browser

geo:lat,lng uri does not work in phone gap

Im quite new to phone gap and mobile app development.
I want to use the geo: uri format to open the google maps application but it does not work.
From what I understand I should be able to just add a line like:
test
but when I click on the "test" link nothing happens. I created an apk and loaded it onto my device and in the console I get an error 404 not found error for the link geo:38.897096,-77.036545
I found comment that there needs to be an app on the device with the uri associated to the app. the Google Maps app is definitely installed on the device.
I can't find anywhere to set the association for geo: on the phone.
In my config.xml I have an intent line as:
<allow-intent href="geo:*" />
Questions:
Is there some setup in the phone gap app for the geo: uri to work ?
Is there some place on the device to set the association for geo: to
google maps
What am I missing here ? seems so simple. Google searching
indicates people have success - but not me.
regards
gmax
Well I did not find a fix for that method but I found a really simple solution to the actual problem - opening google maps app and get turn by turn instructions.
Two lines of code
var url = "http://maps.google.com/maps?saddr=&daddr=15 south st, tuncurry"
window.open(url, '_system');
works like a charm
saddr is the start address (leave it blank for current location)
daddr is the destination address
I hope this helps someone.

How can I control my direction type preference in the new Google Maps link URLs?

I would like to be able to have a Google Maps direction link which, when opened on mobile (Android), would bring up directions in Google Maps using a specified direction type (e.g. bicycle).
Using the old Google Maps URL parameters you can do,
https://www.google.com/maps/preview?saddr=[insert_from_address_here]&daddr=[insert_to_address_here]&dirflg=[insert_mode_here]
but it doesn't work on mobile.
Using the new Google Maps URL parameters you can do,
https://www.google.com/maps/dir/[customer address]/[our address]/am=t/
which does work on mobile but I don't know how to specify direction type.
From the Google Forum itself, try this on your URL if this works.
Car /data=!4m2!4m1!3e0
Bicycling /data=!4m2!4m1!3e1
Walking /data=!4m2!4m1!3e2
Public Transit /data=!4m2!4m1!3e3
Airplane /data=!4m2!4m1!3e4
For example
https://www.google.com/maps/dir/747+Howard+St,+San+Francisco,+CA/55+Music+Concourse+Dr,+San+Francisco,+CA/data=!4m2!4m1!3e3
For more information, juct check the link above and this stackexchange question.

Google Maps Android API v2 in China - map load took around an hour

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.

Mobile web driving directions from current location

I'm building a mobile-version of a website, trying to have one-click link to launch Google Maps with driving directions to the business, from the user's current location. I have it working fine for the iPhone, but when testing on Android, it views 'Current%20Location' and tries to find a business called 'Current Location'. Here is my current code:
Get Directions
I need a universal string to search from the current location, and can't find a definitive answer anywhere online.
Thanks in advance for any help!
I am doing the same thing and now have it working on Android. I don't have an iPhone so I have no way of testing on that. You should leave the saddr parameter blank in the URL, and Google Maps will then prefill it with the user's current location. Also, use + signs instead of spaces in the destination address. Here's the corrected URL:
http://maps.google.com/maps?saddr=&daddr=123+Street+Rd,Cityville,MD,21098
Use the google gps api to get the currentlocation and pass it to maps. Even better I think there's an action to open the built-in maps application asking it to route from current location to your address.
This article on location services should help http://developer.android.com/guide/topics/location/index.html
If you're trying to do it fully through the web, I think the user has to enable location services on the google webpage for it to work.
Also, check out this javascript library that provides a platform neutral api for gps services on most devices http://code.google.com/p/geo-location-javascript/
Google Maps with directions from current location
https://maps.google.com/maps?saddr=&daddr=35.658157,139.697174&sensor=TRUE
https://maps.google.com/maps?saddr=&daddr= PLUS
"location's_latitude" PLUS
"," PLUS
"location's_longitude" PLUS
"&sensor=TRUE" // for getting your current location
Probably the most accurate way using lat and long
<span class="addressAt">
<a href="http://maps.google.com/maps?f=d&hl=en&region=US&doflg=ptm&geocode=&saddr=&daddr=41.75553,-88.322048" target="_blank">213 S River St
Aurora, IL</a>
</span>
This is the only way to get an accurate "my location" on the google maps mobile site. Replace the coordinates(41.75553,-88.322048) with your locations coords. All other ways just wrote in my location as the start address without actually getting the real time location.

Categories

Resources