Skip to content

Instantly share code, notes, and snippets.

@mmcloughlin
Last active June 4, 2018 23:08
Show Gist options
  • Select an option

  • Save mmcloughlin/9ac0f6df2cf14a033facbd47dc9aa9b6 to your computer and use it in GitHub Desktop.

Select an option

Save mmcloughlin/9ac0f6df2cf14a033facbd47dc9aa9b6 to your computer and use it in GitHub Desktop.
package main
import (
"image/color"
"log"
"os"
"github.com/mmcloughlin/geohash"
kml "github.com/twpayne/go-kml"
"github.com/twpayne/go-kml/icon"
)
func main() {
lat, lng := 35.716345, 51.423306
doc := kml.Document()
k := kml.KML(doc)
gs := geohash.EncodeWithPrecision(lat, lng, 7)
gns := geohash.Neighbors(gs)
for _, v := range gns {
box := geohash.BoundingBox(v)
clat, clng := box.Center()
doc.Add(kml.Placemark(
kml.Name(v+" center"),
kml.Style(kml.IconStyle(kml.Icon(kml.Href(icon.PushpinHref("blue"))))),
kml.Point(
kml.Coordinates(kml.Coordinate{Lon: clng, Lat: clat}),
),
))
rlat, rlng := box.Round()
doc.Add(kml.Placemark(
kml.Name(v+" round"),
kml.Style(kml.IconStyle(kml.Icon(kml.Href(icon.PushpinHref("ylw"))))),
kml.Point(
kml.Coordinates(kml.Coordinate{Lon: rlng, Lat: rlat}),
),
))
doc.Add(kml.GroundOverlay(
kml.Name(v),
kml.Color(color.RGBA{R: 255, G: 0, B: 0, A: 128}),
kml.LatLonBox(
kml.North(box.MaxLat),
kml.South(box.MinLat),
kml.East(box.MaxLng),
kml.West(box.MinLng),
),
))
}
if err := k.WriteIndent(os.Stdout, "", " "); err != nil {
log.Fatal(err)
}
}
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>tnke4nj center</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.42356872558594,35.71723937988281</coordinates>
</Point>
</Placemark>
<Placemark>
<name>tnke4nj round</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.423,35.717</coordinates>
</Point>
</Placemark>
<GroundOverlay>
<name>tnke4nj</name>
<color>800000ff</color>
<LatLonBox>
<north>35.717926025390625</north>
<south>35.716552734375</south>
<east>51.42425537109375</east>
<west>51.422882080078125</west>
</LatLonBox>
</GroundOverlay>
<Placemark>
<name>tnke4nn center</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.42494201660156,35.71723937988281</coordinates>
</Point>
</Placemark>
<Placemark>
<name>tnke4nn round</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.425000000000004,35.717</coordinates>
</Point>
</Placemark>
<GroundOverlay>
<name>tnke4nn</name>
<color>800000ff</color>
<LatLonBox>
<north>35.717926025390625</north>
<south>35.716552734375</south>
<east>51.425628662109375</east>
<west>51.42425537109375</west>
</LatLonBox>
</GroundOverlay>
<Placemark>
<name>tnke4jy center</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.42494201660156,35.71586608886719</coordinates>
</Point>
</Placemark>
<Placemark>
<name>tnke4jy round</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.425000000000004,35.716</coordinates>
</Point>
</Placemark>
<GroundOverlay>
<name>tnke4jy</name>
<color>800000ff</color>
<LatLonBox>
<north>35.716552734375</north>
<south>35.715179443359375</south>
<east>51.425628662109375</east>
<west>51.42425537109375</west>
</LatLonBox>
</GroundOverlay>
<Placemark>
<name>tnke4jw center</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.42494201660156,35.71449279785156</coordinates>
</Point>
</Placemark>
<Placemark>
<name>tnke4jw round</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.425000000000004,35.714</coordinates>
</Point>
</Placemark>
<GroundOverlay>
<name>tnke4jw</name>
<color>800000ff</color>
<LatLonBox>
<north>35.715179443359375</north>
<south>35.71380615234375</south>
<east>51.425628662109375</east>
<west>51.42425537109375</west>
</LatLonBox>
</GroundOverlay>
<Placemark>
<name>tnke4jt center</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.42356872558594,35.71449279785156</coordinates>
</Point>
</Placemark>
<Placemark>
<name>tnke4jt round</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.423,35.714</coordinates>
</Point>
</Placemark>
<GroundOverlay>
<name>tnke4jt</name>
<color>800000ff</color>
<LatLonBox>
<north>35.715179443359375</north>
<south>35.71380615234375</south>
<east>51.42425537109375</east>
<west>51.422882080078125</west>
</LatLonBox>
</GroundOverlay>
<Placemark>
<name>tnke4js center</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.42219543457031,35.71449279785156</coordinates>
</Point>
</Placemark>
<Placemark>
<name>tnke4js round</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.422000000000004,35.714</coordinates>
</Point>
</Placemark>
<GroundOverlay>
<name>tnke4js</name>
<color>800000ff</color>
<LatLonBox>
<north>35.715179443359375</north>
<south>35.71380615234375</south>
<east>51.422882080078125</east>
<west>51.4215087890625</west>
</LatLonBox>
</GroundOverlay>
<Placemark>
<name>tnke4ju center</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.42219543457031,35.71586608886719</coordinates>
</Point>
</Placemark>
<Placemark>
<name>tnke4ju round</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.422000000000004,35.716</coordinates>
</Point>
</Placemark>
<GroundOverlay>
<name>tnke4ju</name>
<color>800000ff</color>
<LatLonBox>
<north>35.716552734375</north>
<south>35.715179443359375</south>
<east>51.422882080078125</east>
<west>51.4215087890625</west>
</LatLonBox>
</GroundOverlay>
<Placemark>
<name>tnke4nh center</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.42219543457031,35.71723937988281</coordinates>
</Point>
</Placemark>
<Placemark>
<name>tnke4nh round</name>
<Style>
<IconStyle>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>51.422000000000004,35.717</coordinates>
</Point>
</Placemark>
<GroundOverlay>
<name>tnke4nh</name>
<color>800000ff</color>
<LatLonBox>
<north>35.717926025390625</north>
<south>35.716552734375</south>
<east>51.422882080078125</east>
<west>51.4215087890625</west>
</LatLonBox>
</GroundOverlay>
</Document>
</kml>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment