How to generate the Google Maps URL from GPS coordinates?

1,212 views
Skip to first unread message

Arun Jayapal

unread,
Dec 11, 2019, 3:21:27 AM12/11/19
to Tasker
Hi,

When I receive a SMS from some selected contacts with message Where are you? I reply (via SMS) to the user my current google maps location url. I have written a tasker profile for this.

Profile description as follows:

    Profile: Ask Where In Sms (66)
    Event: Received Text [ Type:Any Sender:CG:Group1 Content:* ]
    Enter: Sms React (67)
    A1: Variable Set [ Name:%message To:%SMSRB Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ] 
    A2: Variable Set [ Name:%sendername To:%SMSRN Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ] 
    A3: Variable Set [ Name:%number To:%SMSRF Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ] 
    A4: Flash [ Text:%sendername (%number):
    %message Long:On ] 
    A5: If [ %message ~R [Ww]here are you? ]
    A6: Get Location [ Source:GPS Timeout (Seconds):10 Continue Task Immediately:Off Keep Tracking:Off ] 
    A7: Variable Set [ Name:%coord To:%LOC Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ] 
    A8: JavaScriptlet [ Code:function func(dms, type){
    
        var sign = 1, Abs=0;
        var days, minutes, secounds, direction;
    
        if(dms < 0)  { sign = -1; }
        Abs = Math.abs( Math.round(dms * 1000000.));
        //Math.round is used to eliminate the small error caused by rounding in the computer:
        //e.g. 0.2 is not the same as 0.20000000000284
        //Error checks
        if(type == "lat" && Abs > (90 * 1000000)){
            //alert(" Degrees Latitude must be in the range of -90. to 90. ");
            return false;
        } else if(type == "lon" && Abs > (180 * 1000000)){
            //alert(" Degrees Longitude must be in the range of -180 to 180. ");
            return false;
        }
    
        days = Math.floor(Abs / 1000000);
        minutes = Math.floor(((Abs/1000000) - days) * 60);
        secounds = ( Math.floor((( ((Abs/1000000) - days) * 60) - minutes) * 100000) *60/100000 ).toFixed();
        days = days * sign;
        if(type == 'lat') direction = days<0 ? 'S' : 'N';
        if(type == 'lon') direction = days<0 ? 'W' : 'E';
        //else return value     
        return (days * sign) + 'º' + minutes + "'" + secounds + "\"" + direction;
    }
    
    let parts = coord.split(',').map(parseFloat)
    
    let lat = parts[0];
    let lon = parts[1];
    
    let latstr = func(lat,'lat');
    let lonstr = func(lon,'lon');
    
    var latlonstr = escape(`${latstr}+${lonstr}`); Libraries: Auto Exit:On Timeout (Seconds):45 ] 
    A9: Variable Set [ Name:%mapsurl To:https://www.google.com/maps/place/%latlonstr/@%coord,15z Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ] 
    A10: Variable Set [ Name:%reply To:I am here: %mapsurl Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ] 
    A11: Send SMS [ Number:%number Message:%reply Store In Messaging App:Off SIM Card: ] 
    


In brief here are the steps I do in the task:

1. receive the message and store the body and sender into a variable
2. get location
3. Compute the coordinates in degrees-minutes-seconds format (DMS) and store into a variable
4. compose reply and send

However, that URL doesn't open in Google Maps app; the app launches but, it doesn't drop a location marker to my current location.

I have the following observations:

1. In the google maps app, the url pattern is different.
2. The url in the sms reply work in the phone's browser

Is there some android maps API which could give me the Google Maps (deep link) url for the same purpose?

- Arun

PS: You need two people at different locations to test this!!!

João Dias

unread,
Dec 11, 2019, 3:57:04 AM12/11/19
to tas...@googlegroups.com
I recommend using Tasker beta and the new Get Location v2 action which gives you this right away :)

Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias

Message has been deleted

João Dias

unread,
Dec 11, 2019, 4:32:24 AM12/11/19
to tas...@googlegroups.com
Yes I am :) It's expected to roll out for everyone this week!

Arun Jayapal

unread,
Dec 11, 2019, 4:32:33 AM12/11/19
to Tasker
Cool. 

I am curious. Are you using any java android APIs for this? Can I implement it in the current Tasker release? (v5.8.5)

When is this expected to release?

Rich D

unread,
Dec 11, 2019, 5:30:20 AM12/11/19
to Tasker Google Groups Post
I use a get location action then send this in the text message.





Steve L

unread,
Dec 12, 2019, 3:40:50 AM12/12/19
to Tasker
If you use Rich's suggestion, you may have to drop the LOC off of the end. For some people, the LOC at the end always puts you at the Library of Congress.

João Dias

unread,
Dec 12, 2019, 4:14:06 AM12/12/19
to tas...@googlegroups.com
Just FYI, 5.9 is now public so go use Get Location V2! :)

Arun Jayapal

unread,
Dec 13, 2019, 4:32:20 AM12/13/19
to Tasker
This one open in Google Maps, however, doesn't center to the location...

I have resorted to the following alternative however:


It opens in the browser but shows you the location.

João Dias

unread,
Dec 13, 2019, 6:43:22 AM12/13/19
to tas...@googlegroups.com
Why aren't you using Get Location v2? It's much easier to do that. It gives you the URL right away :)

Steve L

unread,
Dec 14, 2019, 6:33:06 AM12/14/19
to Tasker
The get location v2 is accurate, but Google tends to move me 150 feet or more from where I really am, especially in town.

A user found this on reddit somewhere and while it was created before the get location v2, it has remained very useful for me.

https://taskernet.com/shares/?user=AS35m8nRNm5oKC95b4yIIS3v8setw1hGNEwUB3ka%2F5gXfn85MvgrPXA9hBy9RfXpRMd1JOYDmSPKhg%3D%3D&id=Task%3AWhere+Are+You

João Dias

unread,
Dec 16, 2019, 5:37:09 AM12/16/19
to tas...@googlegroups.com
Thanks. But does that happen if you set minimum accuracy to something like 10 meters?

Steve L

unread,
Dec 16, 2019, 7:10:24 PM12/16/19
to Tasker
Location accuracy is set as high as I can get. The problem isnt the latitude/ longitude, the problem is Google. Their AI mapping addresses in town sometimes have it backwards.

My family are (for the most part), technologically challenged and need a simple address vs lat,long. Google helps for them, but it really has issues.

For my house, Google has two addresses, one is at the other end of the block and across the street. For another family member, she lives outside a rural town and Google loves putting her house nearly 20 miles North of where it really is, because of the rural addressing system in use.

So while Google does provide good directions for the most part, the addressing scheme they use needs a lot of attention.

Even the Where are you at profile I linked above seems to drop the lat/long to Google for an address. That's the only part that doesnt work quite right.

Reply all
Reply to author
Forward
0 new messages