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

  • SEARCH
  • Home
  • 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 6598441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:20:59+00:00 2026-05-25T18:20:59+00:00

I have two locations (markers) to display on a google map, one is a

  • 0

I have two locations (markers) to display on a google map, one is a static variable called “companyLocale”. The second is a dynamic variable based on your current location “initialLocation”. I am trying to group them into an array called “localArray” but I can’t get the “companyLocale” variable to display within the array . Can someone please help me?

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: iPhone Geolocation</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

var initialLocation;
var companyLocale = new google.maps.LatLng(33.206060, -117.111951);
var localArray = [initialLocation,companyLocale];

var noGeo = new google.maps.LatLng(40.69847032728747, -73.9514422416687);

function initialize() {
  var myOptions = {
    zoom: 14,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  // Safari supports the W3C Geolocation method
  if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
      var placeMarker = new google.maps.Marker({
        position: initialLocation,
        map: map,
      });
      map.setCenter(initialLocation);
    }, function() {
      handleNoGeolocation(browserSupportFlag);
    });
  } else {
    // Browser doesn't support Geolocation
    handleNoGeolocation();
  }

  function handleNoGeolocation() {
    initialLocation = noGeo;
    map.setCenter(initialLocation);
  }
}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
  • 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-05-25T18:20:59+00:00Added an answer on May 25, 2026 at 6:20 pm

    You’re populating localArray with the two values before your initialize function gets called. As you’ve already defined companyLocale as a LatLng, that one is fine, but you don’t create the initialLocation LatLng until later in your execution.

    I would say remove initialLocation from the array initially. Then after you create it, add it into the array. I don’t know if the order of the array items is important here for you or not. If it isn’t, just use .push() to append it into the array. Otherwise use unshift() to prepend it.

    <script type="text/javascript">
    
    var initialLocation;
    var companyLocale = new google.maps.LatLng(33.206060, -117.111951);
    var localArray = [companyLocale];
    
    var noGeo = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
    
    function initialize() {
      var myOptions = {
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
      // Safari supports the W3C Geolocation method
      if(navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
          initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
    
          localArray.unshift(initialLocation);
    
          var placeMarker = new google.maps.Marker({
            position: initialLocation,
            map: map,
          });
          map.setCenter(initialLocation);
        }, function() {
          handleNoGeolocation(browserSupportFlag);
        });
      } else {
        // Browser doesn't support Geolocation
        handleNoGeolocation();
      }
    
      function handleNoGeolocation() {
        initialLocation = noGeo;
        localArray.unshift(initialLocation );
        map.setCenter(initialLocation);
      }
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which requires plotting two locations on google map ? One
We have two databases, in two separate locations. One of the databases resides in
i have one image upload script which upload same image on two locations same
I have two different receive ports and two receive locations - one location assigned
I have two tables, Locations and Facilities They map to two classes, public Location
We have two different ldap providers in two different physical office locations. When I
Hypothetically I have two tables Employee and Locations. Additionaly I have a view viewEmpLocation
In PHP, I have the following code for calculating the distance between two locations:
I have two Python scripts in two different locations and cannot be moved. What
I have two tables, locations and location groups CREATE TABLE locations ( location_id INT

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.