Skip to content

Instantly share code, notes, and snippets.

@gshackles gshackles/caviar.js
Created Aug 30, 2015

Embed
What would you like to do?
Caviar's Courier Tracking Snippet
var delivery_point = new google.maps.LatLng(redacted, redacted);
var mapOptions = {
auto_zoom: true,
zoom: 13,
center: delivery_point
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var out_for_delivery = false;
var street_address_text = "redacted";
var courier_lat = redacted;
var courier_lng = redacted;
var courier_icon, courier_icon_size, courier_image, courier_point, courier_marker;
if (window.devicePixelRatio > 1.5) {
courier_icon = "https://img.trycaviar.com/0rzILkJUpsMvfFPa7Gz09Ri4NTE=/https://s3.amazonaws.com/trycaviar.com/markers/pin-courier-updated-2x.png";
courier_icon_size = new google.maps.Size(80, 80);
} else {
courier_icon = "https://img.trycaviar.com/f0eDQ9tRZpNBBrYllSKO62EohdY=/https://s3.amazonaws.com/trycaviar.com/markers/pin-courier-updated.png";
courier_icon_size = new google.maps.Size(40, 40);
}
if (out_for_delivery) {
courier_image = {
anchor: new google.maps.Point(20, 20),
url: courier_icon,
size: courier_icon_size,
scaledSize: new google.maps.Size(40, 40)
};
courier_point = new google.maps.LatLng(courier_lat, courier_lng);
courier_marker = new google.maps.Marker({
position: courier_point,
title: 'Driver',
description: 'Driver',
icon: courier_image,
map: map
});
var dropoff_marker = new google.maps.Marker({
position: delivery_point,
title: street_address_text,
description: street_address_text,
map: map
});
var bounds = new google.maps.LatLngBounds();
bounds.extend(courier_marker.getPosition());
bounds.extend(dropoff_marker.getPosition());
map.fitBounds(bounds);
} else {
var marker = new google.maps.Marker({
position: delivery_point,
title: street_address_text,
description: street_address_text,
map: map
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.