// Geocode returns the first point returned by MapQuest's geocoding service or an error
// if one occurs during the geocoding request.
515643
func (g *MapQuestGeocoder) Geocode(address string) (*Point, error) {

	queryStr, err := mapquestGeocodeQueryStr(address)
	if err != nil {
		return nil, err
	}

	data, err := g.Request(queryStr)
	if err != nil {
		return nil, err
	}

	res := []*mapQuestGeocodeResponse{}
	json.Unmarshal(data, &res)

	if len(res) == 0 {
		return &Point{}, mapquestZeroResultsError
	}

	lat, err := strconv.ParseFloat(res[0].Lat, 64)
	if err != nil {
		return nil, err
	}

	lng, err := strconv.ParseFloat(res[0].Lng, 64)
	if err != nil {
		return nil, err
	}

	p := &Point{
		lat: lat,
		lng: lng,
	}

	return p, nil
}
978881
func (q *GeoDistanceQuery) Source() (interface{}, error) {
	// {
	//   "geo_distance" : {
	//       "distance" : "200km",
	//       "pin.location" : {
	//           "lat" : 40,
	//           "lon" : -70
	//       }
	//   }
	// }

	source := make(map[string]interface{})

	params := make(map[string]interface{})

	if q.geohash != "" {
		params[q.name] = q.geohash
	} else {
		location := make(map[string]interface{})
		location["lat"] = q.lat
		location["lon"] = q.lon
		params[q.name] = location
	}

	if q.distance != "" {
		params["distance"] = q.distance
	}
	if q.distanceType != "" {
		params["distance_type"] = q.distanceType
	}
	if q.queryName != "" {
		params["_name"] = q.queryName
	}

	source["geo_distance"] = params

	return source, nil
}
361758
func (d dataGeocoder) Geocode(address string) (*geo.Location, error) {
	addr := geo.Address{
		FormattedAddress: address,
	}
	if l, ok := d.AddressToLocation[addr]; ok {
		return &l, nil
	}

	return nil, nil
}
694397
func NewGeoDistanceQuery(lat, lon float64, distance string) *GeoDistanceQuery {
	q := &GeoDistanceQuery{newFtsQueryBase()}
	q.options["location"] = []float64{lon, lat}
	q.options["distance"] = distance
	return q
}
932911
func main() {
	args := map[string]string{}
	gp := geopattern.URIimage(args)
	fmt.Println(gp)
}
84725
func checkGeoKey() error {
	if _, err := geocode.GetAPIKey(); err == nil {
		return nil
	}
	keyPath, err := geocode.GetAPIKeyPath()
	if err != nil {
		return fmt.Errorf("error getting Geocoding API key path: %v", err)
	}
	if env.OnGCE() {
		keyPath = strings.TrimPrefix(keyPath, "/gcs/")
		return fmt.Errorf("for location related requests to properly work, you need to create a Google Geocoding API Key (see https://developers.google.com/maps/documentation/geocoding/get-api-key ), and save it in your VM's configuration bucket as: %v", keyPath)
	}
	return fmt.Errorf("for location related requests to properly work, you need to create a Google Geocoding API Key (see https://developers.google.com/maps/documentation/geocoding/get-api-key ), and save it in Perkeep's configuration directory as: %v", keyPath)
}
914751
func BatchGeocode(addresses []string) ([]LatLng, error) {
	var next, start, end int
	n := len(addresses)
	latLngs := make([]LatLng, n)
	batches := n/100 + 1
	next = 0
	for batch := 0; batch < batches; batch++ {
		start = next
		next = (batch + 1) * 100
		if n < next {
			end = n
		} else {
			end = next
		}
		bgb := batchGeocodeBody{
			Locations:  addresses[start:end],
			MaxResults: 1,
			ThumbMaps:  false,
		}
		b, err := json.Marshal(bgb)
		if err != nil {
			return nil, err
		}
		body := bytes.NewBuffer(b)
		resp, err := http.Post(batchGeocodeURL+apiKey, "application/json", body)
		if err != nil {
			return nil, err
		}
		defer resp.Body.Close()
		var result geocodingResults
		err = decoder(resp).Decode(&result)
		if err != nil {
			return nil, err
		}
		for i, r := range result.Results {
			if len(r.Locations) == 0 {
				latLngs[start+i] = LatLng{Lat: 0, Lng: 0}
			} else {
				latLngs[start+i] = r.Locations[0].LatLng
			}
		}
	}
	return latLngs, nil
}
347676
func (p Point) ToGeoJSON() *geojson.Feature {
	return geojson.NewPointFeature([]float64{p[0], p[1]})
}
13117
func (s GeoDistanceSort) Source() interface{} {
	source := make(map[string]interface{})
	x := make(map[string]interface{})
	source["_geo_distance"] = x

	// Points
	ptarr := make([]interface{}, 0)
	for _, pt := range s.points {
		ptarr = append(ptarr, pt.Source())
	}
	for _, geohash := range s.geohashes {
		ptarr = append(ptarr, geohash)
	}
	x[s.fieldName] = ptarr

	if s.unit != "" {
		x["unit"] = s.unit
	}
	if s.geoDistance != nil {
		x["distance_type"] = *s.geoDistance
	}

	if !s.ascending {
		x["reverse"] = true
	}
	if s.sortMode != nil {
		x["mode"] = *s.sortMode
	}
	if s.nestedFilter != nil {
		x["nested_filter"] = s.nestedFilter.Source()
	}
	if s.nestedPath != nil {
		x["nested_path"] = *s.nestedPath
	}
	return source
}
949249
func (ex Example) GoCode() string {
	var buf bytes.Buffer
	m := exampleFuncMap
	if fMap, ok := exampleCustomizations[ex.API.PackageName()]; ok {
		m = fMap
	}
	tmpl := exampleTmpls.Funcs(m)
	if err := tmpl.ExecuteTemplate(&buf, "example", &ex); err != nil {
		panic(err)
	}

	return strings.TrimSpace(buf.String())
}
1166300
func (c *cmdable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd {
	args := make([]interface{}, 2+3*len(geoLocation))
	args[0] = "geoadd"
	args[1] = key
	for i, eachLoc := range geoLocation {
		args[2+3*i] = eachLoc.Longitude
		args[2+3*i+1] = eachLoc.Latitude
		args[2+3*i+2] = eachLoc.Name
	}
	cmd := NewIntCmd(args...)
	c.process(cmd)
	return cmd
}
1199846
func GeocoderWithURL(nominatimURL string) geo.Geocoder {
	return geo.HTTPGeocoder{
		EndpointBuilder:       baseURL(nominatimURL),
		ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} },
	}
}
958875
func (e *Encoder) Encode(geom orb.Geometry) error {
	if geom == nil {
		return nil
	}

	switch g := geom.(type) {
	// nil values should not write any data. Empty sizes will still
	// write and empty version of that type.
	case orb.MultiPoint:
		if g == nil {
			return nil
		}
	case orb.LineString:
		if g == nil {
			return nil
		}
	case orb.MultiLineString:
		if g == nil {
			return nil
		}
	case orb.Polygon:
		if g == nil {
			return nil
		}
	case orb.MultiPolygon:
		if g == nil {
			return nil
		}
	case orb.Collection:
		if g == nil {
			return nil
		}
	// deal with types that are not supported by wkb
	case orb.Ring:
		if g == nil {
			return nil
		}
		geom = orb.Polygon{g}
	case orb.Bound:
		geom = g.ToPolygon()
	}

	var b []byte
	if e.order == binary.LittleEndian {
		b = []byte{1}
	} else {
		b = []byte{0}
	}

	_, err := e.w.Write(b)
	if err != nil {
		return err
	}

	if e.buf == nil {
		e.buf = make([]byte, 16)
	}

	switch g := geom.(type) {
	case orb.Point:
		return e.writePoint(g)
	case orb.MultiPoint:
		return e.writeMultiPoint(g)
	case orb.LineString:
		return e.writeLineString(g)
	case orb.MultiLineString:
		return e.writeMultiLineString(g)
	case orb.Polygon:
		return e.writePolygon(g)
	case orb.MultiPolygon:
		return e.writeMultiPolygon(g)
	case orb.Collection:
		return e.writeCollection(g)
	}

	panic("unsupported type")
}
101641
func (q *GeoPolygonQuery) AddGeoPoint(point *GeoPoint) *GeoPolygonQuery {
	q.points = append(q.points, point)
	return q
}
1043317
func (p *PostGISPoint) Scan(value interface{}) error {
	if value == nil {
		*p = PostGISPoint{}
		return nil
	}

	v, ok := value.([]byte)
	if !ok {
		return fmt.Errorf("PostGISPoint.Scan: expected []byte, got %T (%v)", value, value)
	}

	ewkb := make([]byte, hex.DecodedLen(len(v)))
	n, err := hex.Decode(ewkb, v)
	if err != nil {
		return err
	}

	var ewkbP ewkbPoint
	err = binary.Read(bytes.NewReader(ewkb[:n]), binary.LittleEndian, &ewkbP)
	if err != nil {
		return err
	}

	if ewkbP.ByteOrder != 1 || ewkbP.WkbType != 0x20000001 || ewkbP.SRID != 4326 {
		return fmt.Errorf("PostGISPoint.Scan: unexpected ewkb %#v", ewkbP)
	}
	*p = ewkbP.Point
	return nil
}
363408
func FullGeocode(address string) (*GeocodingResult, error) {
	// Query Provider
	resp, err := http.Get(geocodeURL + url.QueryEscape(address) + "&key=" + apiKey)

	if err != nil {
		return nil, fmt.Errorf("Error geocoding address: <%v>", err)
	}

	defer resp.Body.Close()

	// Decode our JSON results
	var result GeocodingResult
	err = decoder(resp).Decode(&result)

	if err != nil {
		return nil, fmt.Errorf("Error decoding geocoding result: <%v>", err)
	}

	return &result, nil
}
479800
func Encode(g geom.T) (kml.Element, error) {
	switch g := g.(type) {
	case *geom.Point:
		return EncodePoint(g), nil
	case *geom.LineString:
		return EncodeLineString(g), nil
	case *geom.LinearRing:
		return EncodeLinearRing(g), nil
	case *geom.MultiLineString:
		return EncodeMultiLineString(g), nil
	case *geom.MultiPoint:
		return EncodeMultiPoint(g), nil
	case *geom.MultiPolygon:
		return EncodeMultiPolygon(g), nil
	case *geom.Polygon:
		return EncodePolygon(g), nil
	case *geom.GeometryCollection:
		return EncodeGeometryCollection(g)
	default:
		return nil, geom.ErrUnsupportedType{Value: g}
	}
}