Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Restaurant Review
lenox Offline
Junior Member
**
Posts: 15
Joined: Mar 2018
Post: #41
RE: Restaurant Review
Hi
is there a way to use the Geolocation API https://developers.google.com/maps/docum...https://developers.google.com/maps/documentation/javascript/g to specify the location?

I have tried to extend the resrev_newthread template with the script code. I can then allow the location to be used in the browser but the location is not used on the map.

The template looks like this  (changes from line 53)

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAV6idNxxxxxxxxxxxxxx2PqWWw&callback=initMap">
  </script>
<script type="text/javascript">
var geocoder, map, map2;
function initialize() {
	geocoder = new google.maps.Geocoder();
	var geont = "{$GLOBALS['tplvars']['resrev_geo']}";
	var myLatlng2 =  new google.maps.LatLng{$GLOBALS['tplvars']['resrev_geo']};
	if(geont == ""){
		myLatlng2 =  new google.maps.LatLng(51.165691,10.451526);
	}
	var myOptions2 = {
		zoom: 5,
		center: myLatlng2,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map2 = new google.maps.Map(document.getElementById('map_geol'), myOptions2);
	var marker2 = new google.maps.Marker({
		position: myLatlng2, 
		map: map2
	});
	var myLatlng = new google.maps.LatLng{$GLOBALS['tplvars']['resrev_geo']};
	var myOptions = {
		zoom: 4,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map = new google.maps.Map(document.getElementById('map_postbit'), myOptions);
	var marker = new google.maps.Marker({
		position: myLatlng, 
		map: map
	});
}

function codeAddress() {
	var address = document.getElementById('xthreads_resrev_location').value;
	geocoder.geocode({'address': address}, function(results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			var mylocation = results[0].geometry.location;
			map2.setCenter(mylocation);
			var marker3 = new google.maps.Marker({
				map: map2,
				position: mylocation
			});
			document.getElementsByName("xthreads_resrev_geo")[0].value = mylocation;
		} else {
			alert("Geocode was not successful for the following reason: " + status);
		}
	});
}
</script>
	 <div id="resrev_geo"></div>
    <script>
      // Note: This example requires that you consent to location sharing when
      // prompted by your browser. If you see the error "The Geolocation service
      // failed.", it means you probably did not give permission for the browser to
      // locate you.
      var map, infoWindow;
      function initMap() {
        map = new google.maps.Map(document.getElementById('resrev_geo'), {
          center: {lat: -51.165691, lng: 10.451526},
          zoom: 6
        });
        infoWindow = new google.maps.InfoWindow;

        // Try HTML5 geolocation.
        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
              lat: position.coords.latitude,
              lng: position.coords.longitude
            };

            infoWindow.setPosition(pos);
            infoWindow.setContent('Location found.');
            infoWindow.open(map);
            map.setCenter(pos);
          }, function() {
            handleLocationError(true, infoWindow, map.getCenter());
          });
        } else {
          // Browser doesn't support Geolocation
          handleLocationError(false, infoWindow, map.getCenter());
        }
      }

      function handleLocationError(browserHasGeolocation, infoWindow, pos) {
        infoWindow.setPosition(pos);
        infoWindow.setContent(browserHasGeolocation ?
                              'Error: The Geolocation service failed.' :
                              'Error: Your browser doesn\'t support geolocation.');
        infoWindow.open(map);
      }
    </script>


Unfortunately I don't know much about maps and the intigration in xthreads and I hope that somebody can help.

Thanks in advance

Greetings lenox

06-17-2020 02:22 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
Restaurant Review - RateU - 08-03-2012, 07:35 AM
RE: Restaurant Review - Jumper - 08-06-2012, 01:46 PM
RE: Restaurant Review - ZiNgA BuRgA - 08-06-2012, 03:45 PM
RE: Restaurant Review - RateU - 08-07-2012, 03:49 AM
RE: Restaurant Review - Jumper - 08-08-2012, 05:30 AM
RE: Restaurant Review - RateU - 08-08-2012, 06:43 AM
RE: Restaurant Review - Jumper - 08-08-2012, 07:39 AM
RE: Restaurant Review - RateU - 08-08-2012, 08:04 AM
RE: Restaurant Review - Jumper - 08-08-2012, 08:27 AM
RE: Restaurant Review - RateU - 08-09-2012, 04:14 AM
RE: Restaurant Review - Jumper - 08-10-2012, 01:24 PM
RE: Restaurant Review - WhiteEagle - 08-11-2012, 03:50 AM
RE: Restaurant Review - RateU - 08-11-2012, 05:45 AM
RE: Restaurant Review - WhiteEagle - 08-11-2012, 04:34 PM
RE: Restaurant Review - RateU - 08-12-2012, 05:03 AM
RE: Restaurant Review - WhiteEagle - 08-12-2012, 09:10 AM
RE: Restaurant Review - WhiteEagle - 09-02-2012, 04:58 AM
RE: Restaurant Review - RateU - 09-02-2012, 06:27 AM
RE: Restaurant Review - WhiteEagle - 09-02-2012, 06:35 AM
RE: Restaurant Review - RateU - 09-02-2012, 11:42 PM
RE: Restaurant Review - WhiteEagle - 09-03-2012, 12:32 AM
RE: Restaurant Review - RateU - 09-03-2012, 12:50 AM
RE: Restaurant Review - WhiteEagle - 09-03-2012, 01:48 AM
RE: Restaurant Review - RateU - 09-03-2012, 03:18 AM
RE: Restaurant Review - WhiteEagle - 09-03-2012, 02:43 PM
RE: Restaurant Review - ZiNgA BuRgA - 09-03-2012, 03:01 PM
RE: Restaurant Review - WhiteEagle - 09-03-2012, 03:46 PM
RE: Restaurant Review - RateU - 09-04-2012, 01:29 AM
RE: Restaurant Review - WhiteEagle - 09-04-2012, 03:45 AM
RE: Restaurant Review - ZiNgA BuRgA - 09-04-2012, 08:09 AM
RE: Restaurant Review - WhiteEagle - 09-05-2012, 12:16 PM
RE: Restaurant Review - isoka - 04-08-2013, 12:28 AM
RE: Restaurant Review - RateU - 04-08-2013, 01:01 AM
RE: Restaurant Review - isoka - 04-08-2013, 05:13 AM
RE: Restaurant Review - RateU - 04-08-2013, 05:21 AM
RE: Restaurant Review - lenox - 06-24-2018, 06:47 PM
RE: Restaurant Review - Lordikon30 - 01-11-2020, 12:44 PM
RE: Restaurant Review - Lordikon30 - 01-21-2020, 06:43 AM
RE: Restaurant Review - Lordikon30 - 01-24-2020, 09:23 AM
RE: Restaurant Review - RateU - 04-26-2020, 03:19 AM
RE: Restaurant Review - lenox - 06-17-2020 02:22 AM
RE: Restaurant Review - RateU - 06-21-2020, 06:01 AM
RE: Restaurant Review - lenox - 06-21-2020, 11:15 PM
RE: Restaurant Review - RateU - 06-22-2020, 01:11 AM
RE: Restaurant Review - lenox - 06-22-2020, 04:43 AM
RE: Restaurant Review - RateU - 06-22-2020, 04:47 AM
RE: Restaurant Review - Lordikon30 - 10-25-2021, 04:06 AM

 Standard Tools
Forum Jump: