• 0

google map API & XMLHttpRequest


Question

hi can some one check this syntax of this cos i'm missing something it just dont work

The JS


downloadUrl("http://chsites.co.uk/track/inc/maploc.php?id='.$mapid.'&name='.$member['id'].'", function(data) {
var xml = data.responseXML;

var Center = xml.documentElement.getElementsByTagName("marker");
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(
parseFloat(Center.getAttribute("lat")),
parseFloat(Center.getAttribute("lon"))),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
});
}

function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject("Microsoft.XMLHTTP") :
new XMLHttpRequest;

request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};

request.open("GET", url, true);
request.send(null);
}
[/CODE]

The XML

[CODE]
<markers>
<marker lat="51.5589355" lon="0.1463353" speed="1.255" time="17:12:39 - 2012/12/04"/>
</markers>
[/CODE]

Link to comment
https://www.neowin.net/forum/topic/1123722-google-map-api-xmlhttprequest/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

a couple of things Craig.. I just built a semi complex Google Maps module for company I'm involved with.

You can see it here:

http://www.venture51.com/people/

A couple of notes here that might be very obvious:

Google Maps API and markers require Marker library loaded in addition to Google Maps api (not sure if you included it or not)

Take a look at the source code of that page I sent you. You will see what I do.. just go through it and see how I did it.

I am using JSON feed from my database for data and I add them to marker group. If you want to customize and have more functionality I strongly encorouage you to use GoogleMarkerPlus library. You can find it here:

http://google-maps-u...ts_example.html

http://google-maps-u.../reference.html

But the short of it.. your XML should contain your long / lat information and data you want, while you parse and add your markers this way:


var markers = [];

var marker = new google.maps.Marker({
position: latLng,
animation: google.maps.Animation.DROP,
title: markerCity,
visible: true
});

var markerCluster = new MarkerClusterer(map, markers, mcOptions );
[/CODE]

This way you can control the whole marker cluster and use Event handlers on the map with markerclustererplus

if you don't want to work with clusters, you can just define the map in your marker declaration as you loop through your marker xml like this:

[CODE]
var markers = [];

var marker = new google.maps.Marker({
position: latLng,
animation: google.maps.Animation.DROP,
[b]map: map[/b],
visible: true
});

var markerCluster = new MarkerClusterer(map, markers, mcOptions );
[/CODE]

you will notice that I added here the map attribute. That tells this marker when it's created which map it belongs to.

  • 0

sorry looking back i was vague. OK a simple Google map API V3 would be

HTML

<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC9drFQnsmuob_bO9wFITHv-5K2pM-lgD0&sensor=false">
</script>
<script type="text/javascript">
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(LATITUDE,LONGITUDE), //THIS MUST BE A POSITION (you understand)
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
});
</script>[/CODE]

OK this will show a map with the center of the map whatever LATITUDE,LONGITUDE you put in i wish to update the map center every 10 seconds with new coordinates (the script in first post)

  • 0

sorry looking back i was vague. OK a simple Google map API V3 would be

HTML

<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC9drFQnsmuob_bO9wFITHv-5K2pM-lgD0&sensor=false">
</script>
<script type="text/javascript">
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(LATITUDE,LONGITUDE), //THIS MUST BE A POSITION (you understand)
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
});
</script>[/CODE]

OK this will show a map with the center of the map whatever LATITUDE,LONGITUDE you put in i wish to update the map center every 10 seconds with new coordinates (the script in first post)

Ah..that's easy..

If you want to pan to (center the map on a specific lat/long) you do this:

map.panTo(new google.maps.LatLng(latlngArr[0],latlngArr[1]));

My latingArr array is just holding values for lat/lng of new points but you can replace it with your new values.

  • Like 1
  • 0

thanks soooooo much buddy how about this one my polyline is all over the place you can see it here http://chsites.co.uk/track/index.php?page=show_map&id=2

if you click on a flag the speed it not speed its MYSQL id entry (just for testing)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • You can disable all non needed features from Brave. There is also Brave Origin which removes them entirely and it is free for Linux.
    • I wish I could use Brave but the tab suspension feature is horrible. It doesn't suspend them like Edge does. Even after 2h open with 70+ tabs (same as Edge), it has 2GB more consumption than Edge for no reason.
    • TeamViewer 15.78.4.0 by Razvan Serea TeamViewer is the fast, simple and friendly solution for remote access over the Internet - all applications in one single, very affordable module. Remote control of computers over the Internet, Instantly take control over a computer anywhere on the Internet, even through firewalls. No installation required, just use it fast and secure. Training, sales and teamwork, TeamViewer can also be used to present your desktop to a partner on the Internet. Show and share your software, PowerPoint presentations etc. File transfer, chat and more, Share your files, chat, switch the direction during a teamwork session, and a lot more is included in TeamViewer. TeamViewer key features: Cross-platform remote access (Windows, macOS, Linux, Android, iOS, IoT) Attended and unattended remote control Secure file transfer between devices Remote printing to local printers Multi-monitor support with easy switching Wake-on-LAN for sleeping devices Session links for quick connections (no password sharing) Web client access (no installation needed) End-to-end encryption (AES-256) Two-factor authentication and access controls AI-powered session insights and reporting Mass deployment and device management tools Customizable allow/block lists for security Command line and script execution remotely Performance monitoring and analytics dashboards TeamViewer 15.78.4.0 changelog: Improvements Permissions inheritance has been improved, increasing reliability when permissions are assigned to user group managers. Bugfixes Fixed a bug where 'Show details' button was not showing up on command bar upon selection of a device group. Fixed a bug which was causing the legacy groups to disappear when applying hide offline filter in basic view. Fixed a bug where devices were loading infinitely after login. Fixed a bug which was causing crash in application. Download: TeamViewer 15.78.4.0 | 32-bit | Portable | Mac | ~70.0 MB (Free for personal use) View: TeamViewer Home Page | Release Notes | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • But I don't want a Switch 2 to play this game and then collect dust afterwards.
    • I will never use a crypto browser from a shady company because it has a built in adblocker. I am not that desperate and I do care about the ethics of the browser I use. So a Firefox based browser or Adguard is the way to go. I mean the app, not the MV3 extension combined with Adguard assistant extension for controlling everything directly in my browser. I prefer using a firefox based browser or paying 10 bucks for a lifetime license of Adguard than ending up using shady crypto browsers for an adblocker.
  • Recent Achievements

    • One Year In
      Primer1st earned a badge
      One Year In
    • Experienced
      JayZJay went up a rank
      Experienced
    • Reacting Well
      Sir_Timbit earned a badge
      Reacting Well
    • Week One Done
      rubentuben8 earned a badge
      Week One Done
    • Week One Done
      ARaclen earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      524
    2. 2
      PsYcHoKiLLa
      232
    3. 3
      Edouard
      135
    4. 4
      ATLien_0
      88
    5. 5
      Steven P.
      83
  • Tell a friend

    Love Neowin? Tell a friend!