0

I have 2 variables: Latitude and Longitude: I want to insert it like this.

<img src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=15&size=640x640&scale=2&key=example"; Here's my code:

<head>
<script type="text/javascript">


    function TestGeo() {
      if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition( TestMap, error, {maximumAge: 30000, timeout: 10000, enableHighAccuracy: false} );
      } else {
          alert("Sorry, but it looks like your browser does not support geolocation.");
            }
        function TestMap(position) {
            var latitude = position.coords.latitude;
            var longitude = position.coords.longitude;}
        </script>

        </head>
        <body onload="TestGeo();">
        <img src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=15&size=640x640&scale=2&key=example";
        </body>
        </html>
jojoclt
  • 117
  • 1
  • 1
  • 11
  • I don't know which one to use. What do you suggest? Please advice. – jojoclt Dec 29 '16 at 07:12
  • Both language are doable. Where will you need this? frontend or backend server parsing? – Lionel Chan Dec 29 '16 at 07:15
  • Would help if you were a lot more specific about how you expect this to work within your app – charlietfl Dec 29 '16 at 07:19
  • I am going to make a webapp. About clock in and clockout. When person walks into the area of the set location. It will clock in that user in to the server side with timestamp and will return the result as "OK" or "Falied". – jojoclt Dec 29 '16 at 07:23
  • `` then have `document.getElementById(where").src="https://maps.googleapis.com/maps/api/staticmap? center="+latitude+","+longitude+"&zoom=15&size=640x640&scale=2&key=example";` – mplungjan Dec 29 '16 at 07:26
  • @mplungjan not working – jojoclt Dec 29 '16 at 09:26

1 Answers1

0

If you are using javascript . try this

            function TestMap(position) {
            var latitude = position.coords.latitude;
            var longitude = position.coords.longitude;
            var imgsrc = "https://maps.googleapis.com/maps/api/staticmap?center="+latitude+","+longitude+"&zoom=15&size=640x640&scale=2&key=example";
            $('#imgselector').attr('src', imgsrc)
            }

html should be <img src="" id="imgselector"/>

Sharmila
  • 785
  • 4
  • 11