Redirect user to Google Maps app

Asked

Viewed 862 times

4

I’m developing a responsive website and using the Google Maps API to generate the company location map.

I would like when the usurer was accessing the site by a mobile device and the same clicked on the map or even a link, was redirected to the Google Maps application and transfer the route, so he would not need to enter the address and search.

var myCenter = new google.maps.LatLng(-7.0995734, -34.8410316);
 function initialize()
    {
      var mapProp = {
      center: myCenter,
      zoom: 16,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
   var marker = new google.maps.Marker({
                position: myCenter,
            });
           marker.setMap(map);
        }
google.maps.event.addDomListener(window, 'load', initialize);

1 answer

2


I think this code would solve your problem:

javascript:window.open("geo:"+latitude+","+longitude+"" , "_system");

It offers the native option and the google maps for the user, and if you want to open it on iOS:

 javascript:window.open("maps://maps.apple.com/?q=:"+latitude+","+longitude+"");

You can for example create one that receives values in lat long if it is dynamic, but from what I saw your data are static, so it is simpler, go to your html and enter this example code:

<div class="meuMapa"> 
  <a onclick="javascript:window.open('geo:-7.0995734, -34.8410316', '_system')> Clique aqui para abrir seu mapa
  </a>
</div>

Or simply you call a function in your onclick where it checks the device type, for example:

var devicePlatform = (navigator.userAgent.match(/iPad/i))  == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i))  == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "null";
if((devicePlatform == iPhone) || (devicePlatform == iPad))
{
   /*sua chamada de função*/
}
  • Marcos, take a look at my question, I added my code, please see where I can put this line of code you mentioned

  • edited the reply @Sérgiomachado da uma olhada ai

  • I know the code, open the map but open without coordinates, so I did another search on the internet and found the solution: $("#Googlemap"). on('click', Function() { window.Location = "http://maps.google.com/? q=Implantare+Soluções+em+Odontologia/"; });

  • if it worked at all

Browser other questions tagged

You are not signed in. Login or sign up in order to post.