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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:53:08+00:00 2026-06-15T14:53:08+00:00

I have written a PHP and javaScript code which will retrieve latitude and longitude

  • 0

I have written a PHP and javaScript code which will retrieve latitude and longitude informations from Database and place markers on Google map according in appropriate places(using lat and lon values). This works fine.

I need to join these markers and draw route on the map. How to do it.

   <html>
   <head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
   <style type="text/css">
   body { font: normal 10pt Helvetica, Arial; }
    #map { width: 350px; height: 300px; border: 0px; padding: 0px; }
    </style>
   <script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script>
   <script type="text/javascript" src="js/jquery.js"></script>
   <script type="text/javascript">

   var icon = new    google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
   new google.maps.Size(32, 32), new google.maps.Point(0, 0),
   new google.maps.Point(16, 32));
   var center = null;
   var map = null;
   var currentPopup;
   var bounds = new google.maps.LatLngBounds();

  function addMarker(lat, lng, info)
 {
   var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker(
{
    position: pt,
    icon: icon,
    map: map
});
var popup = new google.maps.InfoWindow(
{
    content: info,
    maxWidth: 300
});

google.maps.event.addListener(marker, "click", function()
{
    if (currentPopup != null)
    {
        currentPopup.close();
        currentPopup = null;
    }
    popup.open(map, marker);
    currentPopup = popup;
   });
    google.maps.event.addListener(popup, "closeclick", function()
   {
    map.panTo(center);
    currentPopup = null;
   });
   }

function initMap()
{
 map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(0, 0),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
mapTypeControlOptions:
{
    style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions:
{
style: google.maps.NavigationControlStyle.SMALL
 }
 });


  $.getJSON('googlescript.php', function(items)
  {
   for (var i = 0; i < items.length; i++) {
      (function(item) {
        addMarker(item.lat, item.long, '<b>' + item.name + '</b><br />' + item.desc);
    })(items[i]);
   }
  });

  center = bounds.getCenter();
 map.fitBounds(bounds);

   }
   </script>
    </head>
   <body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
   <div id="map"></div>
    </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-06-15T14:53:09+00:00Added an answer on June 15, 2026 at 2:53 pm

    Modify your JSON return function to something like this:

    $.getJSON('googlescript.php', function(items)
      {
       var routePoints = [];
       for (var i = 0; i < items.length; i++) {
          (function(item) {
            addMarker(item.lat, item.long, '<b>' + item.name + '</b><br />' + item.desc);
        })(items[i]);
        routePoints.push(new google.maps.LatLng(items[i].lat,items[i].long));
       }
       var route= new google.maps.Polyline({
        path: routePoints,
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 2
      });
    
      route.setMap(map);
    
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some JavaScript code that will read from the Google Maps API
I have written PHP code which connects to MYSQL to look up information, sends
I have a multiple row of buttons in my javascript code which goes from
I have a pre-written code in Php where JavaScript function is called echo <a
I have this piece of code written in jQuery and PHP: <script type=text/javascript> $(document).ready(function(){
I have a piece of code written in PHP inside my javascript tag. I
I have, with the help of the SO community written a javascript and php
I have written a PHP application which requires storage of millions of integers between
I have written a PHP function to take a video embed code that has
Below i have written code of a soap webservice in php with its client,It

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.