Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8927865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:18:27+00:00 2026-06-15T08:18:27+00:00

I am new to Javascript and Google Maps and I am trying to add

  • 0

I am new to Javascript and Google Maps and I am trying to add a marker to my map using the information provided on the Google Developers website. Although the map displays as it should on the current position and I am getting no errors on the Javascript console, for some reason the marker is still not showing up. Any ideas on why this is happening? Thanks in advance.

Here is my code:

            function initialize() {
              var myOptions = {
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
              };

              var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

              // Try W3C Geolocation (Preferred)
              if(navigator.geolocation) {
                browserSupportFlag = true;
                navigator.geolocation.getCurrentPosition(function(position) {
                  initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
                  map.setCenter(initialLocation);
                }, function() {
                  handleNoGeolocation(browserSupportFlag);
                });
              }
              // Browser doesn't support Geolocation
              else {
                browserSupportFlag = false;
                handleNoGeolocation(browserSupportFlag);
              }

              function handleNoGeolocation(errorFlag) {
                if (errorFlag == true) {
                  alert("Geolocation service failed.");
                  initialLocation = newyork;
                } else {
                  alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
                  initialLocation = siberia;
                }
                map.setCenter(initialLocation);
              }

                var marker = new google.maps.Marker({
                    position: initialLocation,
                    title:"You are here!"

                 });
                 // should add the marker to the map
                 marker.setMap(map);

            };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:18:30+00:00Added an answer on June 15, 2026 at 8:18 am

    The geolocation service is asynchronous. You need to use the coordinates inside its callback function. Hard to tell from what you posted which path the geolocation is taking, here is code that would do it if it succeeds.

            if(navigator.geolocation) {
                browserSupportFlag = true;
                navigator.geolocation.getCurrentPosition(function(position) {
                  initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
                  map.setCenter(initialLocation);
                  var marker = new google.maps.Marker({
                    position: initialLocation,
                    title:"You are here!"
    
                    });
                  // should add the marker to the map
                  marker.setMap(map);
                }, function() {
                  handleNoGeolocation(browserSupportFlag);
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create map (using the Google Maps JavaScript API V3 ) which
I'm trying to show a custom map using the Google Maps Javascript API. In
I'm using the Google Maps API V3 and I'm trying to make a marker
I'm trying to replicate the following exemple : http://www.leigeber.com/2008/04/map-your-users-using-the-google-maps-api-and-php/ How to integrate this PHP
I'm new to JavaScript and the Google Maps API v3. I'm trying the Developer's
I am new to the Google Maps API v3 and new to Javascript in
New to javascript and such, trying to create a loop for fading logos using
Goal: To render a google map using geolocation. I am trying to implement the
I'm new of javascript language and I'm trying to create a circle using setOptions
I am trying to draw a geodesic polyline with Google Maps JavaScript API from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.