var locations = [
      ['My Aunt house', 11.5609370, 104.8714615],
      ['My teacher house', 11.5609370, 104.8754615],
      ['jing', 11.5609370, 104.8734615],
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 10,
      center: new google.maps.LatLng(11.5609370, 104.8714615),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  var myMarker = new google.maps.Marker({
    position: new google.maps.LatLng(position.coords.latitude,
position.coords.longitude),
  });
  map.setCenter(myMarker.position);
  myMarker.setMap(map);
}
getLocation();

On Sat, Mar 2, 2019 at 5:36 PM Barry Hunter <barrybhun...@gmail.com> wrote:

> Well fundermentally it should be possible. Sounds like some
> incompatibility with how you've combined them.
>
> But without seeing your code its hard to guess what happened.
>
> ... if you post a link to your testing code, there might just be enough of
> us still in this group to take a look.
>
> On Sat, Mar 2, 2019 at 1:02 AM Menghuy <menghuy...@gmail.com> wrote:
>
>> Yeah thank you Barry. I want to know if i could use this 2 functions
>> (geolocation and addmarker) together on the google map api javascript,
>> because the geolocation function not working when there are add marker
>> function on the same code.
>>
>> On Sat, Mar 2, 2019 at 2:04 AM Barry Hunter <barrybhun...@gmail.com>
>> wrote:
>>
>>> Do you mean the browser Geolocation API?
>>> https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API
>>>
>>> ... ie find the visitors location, and then let them create a Marker at
>>> that location?
>>>
>>> Or maybe mean just show a fancy marker to 'show' the user their location?
>>>
>>> ... in short yes, should be able to use Geolocation API with the Maps
>>> API
>>>
>>> Something like this kinda demonstrates what would do...
>>>
>>> navigator.geolocation.getCurrentPosition(function(position) {
>>>   addMarker(position.coords.latitude, position.coords.longitude);});
>>>
>>> function addMarker(lat,lng) {
>>>   var marker = new google.maps.Marker({
>>>     position: {lat: lat, lng: lng},
>>>     map: map
>>>   });
>>> }
>>>
>>>
>>>
>>> On Fri, Mar 1, 2019 at 4:50 PM Menghuy <menghuy...@gmail.com> wrote:
>>>
>>>> Hello,
>>>> I tried to search on Internet a lot, but I couldn't find the answer.
>>>> Is it possible to use geolocation with addmarker function in Google map
>>>> api javascript?
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "[deprecated] Google Maps JavaScript API v3. Please use the latest
>>>> post." group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to google-maps-js-api-v3+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to
>>>> google-maps-js-api-v3@googlegroups.com.
>>>> Visit this group at
>>>> https://groups.google.com/group/google-maps-js-api-v3.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "[deprecated] Google Maps JavaScript API v3. Please use the latest
>>> post." group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to google-maps-js-api-v3+unsubscr...@googlegroups.com.
>>> To post to this group, send email to
>>> google-maps-js-api-v3@googlegroups.com.
>>> Visit this group at
>>> https://groups.google.com/group/google-maps-js-api-v3.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "[deprecated] Google Maps JavaScript API v3. Please use the latest post."
>> group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to google-maps-js-api-v3+unsubscr...@googlegroups.com.
>> To post to this group, send email to
>> google-maps-js-api-v3@googlegroups.com.
>> Visit this group at https://groups.google.com/group/google-maps-js-api-v3
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "[deprecated] Google Maps JavaScript API v3. Please use the latest post."
> group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-maps-js-api-v3+unsubscr...@googlegroups.com.
> To post to this group, send email to
> google-maps-js-api-v3@googlegroups.com.
> Visit this group at https://groups.google.com/group/google-maps-js-api-v3.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"[deprecated] Google Maps JavaScript API v3. Please use the latest post." group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-maps-js-api-v3+unsubscr...@googlegroups.com.
To post to this group, send email to google-maps-js-api-v3@googlegroups.com.
Visit this group at https://groups.google.com/group/google-maps-js-api-v3.
For more options, visit https://groups.google.com/d/optout.

Reply via email to