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 4331294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:05:12+00:00 2026-05-21T10:05:12+00:00

I am using Google Maps V3 and I want to: Set the center of

  • 0

I am using Google Maps V3 and I want to:

  1. Set the center of the map to a particular latlng. I am using:

    map.setCenter(new google.maps.LatLng(mylat,mylong));
    
  2. Set a point in that center spot. I am currently using:

    var point = new google.maps.LatLng(mylat,mylong);
    
    marker = map_create_marker(point,"My Popup",map_icon_red);
    

    With this function:

    function map_create_marker(point,html,icon) {
        var marker =    new google.maps.Marker({
            position: point,
            map: map,
            icon: icon,
            shadow: map_icon_shadow
        });
    
        if(html!="") {
            var infowindow = new google.maps.InfoWindow({
                    content: html
            });
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map,marker);
            });
        }
        return marker;
    }
    
  3. Position many more markers using the same method above

The problem is that when I set the center like above, it only ever displays the first marker. But if I don’t set a center it displays all the markers. How can I get them to both work?

Here is the full javascript code:

<script type="text/javascript"
        src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" language="JavaScript">
    var map;

    var map_icon_green = new google.maps.MarkerImage(
        "http://mysite.com/green_pointer.png",
        new google.maps.Size(12,20),
        new google.maps.Point(0,0));

    var map_icon_blue = new google.maps.MarkerImage(
        "http://mysite.com/blue_pointer.png",
        new google.maps.Size(12,20),
        new google.maps.Point(0,0));

    var map_icon_yellow = new google.maps.MarkerImage(
        "http://mysite.com/yellow_pointer.png",
        new google.maps.Size(12,20),
        new google.maps.Point(0,0));

    var map_icon_red = new google.maps.MarkerImage(
        "http://mysite.com/red_pointer.png",
        new google.maps.Size(12,20),
        new google.maps.Point(0,0));

    var map_icon_shadow = new google.maps.MarkerImage(
        "http://mysite.com/shadow.png",
        new google.maps.Size(28,20),
        new google.maps.Point(-6,0));

    var map_crosshair = new google.maps.MarkerImage(
        "http://mysite.com/cross-hair.gif",
        new google.maps.Size(17,17),
        new google.maps.Point(0,0));


    function map_loader() {
        var myOptions = {
            zoom: 5,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            scrollwheel:false
        }

        map = new google.maps.Map(
                document.getElementById('map_container'), myOptions);

        map.setCenter(new google.maps.LatLng(53.0,-1.0));

        // <![CDATA[
        var point = new google.maps.LatLng(53.0,-4.0755);
        marker = map_create_marker(point,"some html which is OK",map_icon_red);
        // ]]>

        // <![CDATA[
        var point = new google.maps.LatLng(-24.0,25.0);
        marker = map_create_marker(point,"some html which is OK",map_icon_red);
        // ]]>

        // <![CDATA[
        var point = new google.maps.LatLng(54.0,-2.0);
        marker = map_create_marker(point,"some html which is OK",map_icon_red);
        // ]]>

        map.disableDoubleClickZoom = false;
    }


    function map_create_marker(point,html,icon) {
        var marker =    new google.maps.Marker({
            position: point,
            map: map,
            icon: icon,
            shadow: map_icon_shadow
        });

        if(html!="") {
            var infowindow = new google.maps.InfoWindow({
                    content: html
            });
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map,marker);
            });
        }
        return marker;
    }
    var map_set_center = 0;
    function map_load_resize() {
        if(map_set_center==0) {
             map.setCenter(new google.maps.LatLng(53.0,-1.0));
        }
        map_set_center = 1;
    }

    </script>   
  • 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-21T10:05:13+00:00Added an answer on May 21, 2026 at 10:05 am

    Try using this code for v3:

    gMap = new google.maps.Map(document.getElementById('map')); 
    gMap.setZoom(13);      // This will trigger a zoom_changed on the map
    gMap.setCenter(new google.maps.LatLng(37.4419, -122.1419));
    gMap.setMapTypeId(google.maps.MapTypeId.ROADMAP);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the new Google Maps v3 STYLED MAP. I want to change
I want to draw multiple circles on a map, using the Google Maps API
function initialize() { var myOptions = { center: new google.maps.LatLng(23.71181,90.407467), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP
I want to add some custom roads using google maps api (i.e. off-road routes,
I am using the Markercluster plugin for Google Maps API V3. I want to
I am using Google Maps V3 API to display my map. Problem: How can
I'm using google maps autocomplete for user to input the place. after that I
I'm using Google Maps' API and added a few markers in a map. Each
I just started working using Google Maps API yesterday, and trying to set up
I've been using Google Maps Api for a while and I recently checked that

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.