Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I position a marker on a map using GeoLocation?

I am creating a map page with a single image, enter image description here and I would like to use GeoLocation to show where the user is as a blue dot (somewhat like iOS maps).

I already have the JavaScript for finding the location, and it works great. I just need help with how to place a marker - just a simple image - on the page according to the output of position.coords.latitude and position.coords.longitude.

Is there any way that this can be done, and if so, how?
Thanks in advance.

like image 824
CoolJRT Avatar asked Nov 30 '25 12:11

CoolJRT


1 Answers

You can simply use GMarker in your javascript, something like this:

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title:"Hello World!"
});

You can customize its image like that:

var image = 'beachflag.png';
marker.icon = image;
like image 116
VMAtm Avatar answered Dec 03 '25 04:12

VMAtm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!