Skip to content
BestAstroAPI

Place box

A birth place field for any website, with one script.

  • Your visitor types and picks a place.
  • Your form gets latitude, longitude and time zone.
  • No server code and no other API.

1. Add it

  1. Create a website key for your domain on the dashboard's API keys page.
  2. Paste this in your page:
Your page
<label for="birthplace">Birth place</label>
<input id="birthplace" name="birthplace" data-bestastro-place required>

<script src="https://api.bestastroapi.in/site/v1/places.js" data-key="site_live_YOUR_WEBSITE_KEY" defer></script>

It works in:

  • plain HTML
  • React, Vue or Next.js
  • site builders that let you add a script to the page itself

2. What your form sends

The box adds hidden fields to the same form. For a field named birthplace:

  • birthplace: the place as text, for example Gorakhpur, Uttar Pradesh, India
  • birthplace_lat, birthplace_lon: coordinates
  • birthplace_tz: time zone, for example Asia/Kolkata
  • birthplace_place_id: send this as place_id to any calculation
  • The form cannot be sent with a half-typed place.
  • If the search cannot be reached, the visitor is not blocked.
  • Then the typed text is sent and the hidden fields stay empty. Check them on your server.

Use it from JavaScript

Every choice fires an event on the field:

document.addEventListener("bestastro:place", (e) => {
  const p = e.detail;
  console.log(p.label, p.lat, p.lon, p.tz, p.id);
});

In React:

import { useEffect, useRef } from "react";

export function BirthPlace({ onPlace }) {
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current;
    const take = (e) => onPlace(e.detail);
    el.addEventListener("bestastro:place", take);
    return () => el.removeEventListener("bestastro:place", take);
  }, [onPlace]);
  return <input ref={ref} name="birthplace" data-bestastro-place data-prefix="birth_" />;
}

// once, in the page: <script src="https://api.bestastroapi.in/site/v1/places.js" data-key="site_live_YOUR_WEBSITE_KEY" defer></script>
  • Fields that appear later are found on their own.
  • To attach one yourself: BestAstroPlaces.attach(input, { onSelect: (place) => {} })

Options

AttributeWhereMeaning
data-keyscriptYour website key. Required
data-countryscript or fieldTwo-letter code such as IN, to search one country only
data-bestastro-placefieldTurns this text field into a place box
data-prefixfieldStart of the hidden field names. Default: the field's name and an underscore

Moving from Prokerala's location script

  • Change the script address and the id.
  • Fields with the class prokerala-location-input keep working.
  • They fill the same coordinates and timezone fields.
  • Code that calls LocationSearch keeps working too.
- <script src="https://client-api.prokerala.com/static/js/location.min.js"></script>
+ <script src="https://api.bestastroapi.in/site/v1/places.js" data-key="site_live_YOUR_WEBSITE_KEY"></script>

- new LocationSearch(input, onPlace, { clientId: "your-prokerala-client-id" });
+ new LocationSearch(input, onPlace, { clientId: "site_live_YOUR_WEBSITE_KEY" });

Website keys and safety

  • A website key starts with site_live_. It is meant to be seen.
  • It can only search places, and only for pages on the domains you list.
  • Never put a secret key (ba_live_) in a page. The box refuses to start with one.
  • Charts, matching and the rest still need your secret key, on your server.
  • Box searches have their own daily limit and do not use your calls. See Rate limits.
  • Over the limit, the box says that search is not available.
  • A browser reports its page's domain truthfully, but other programs can lie about it.
  • The worst a copied key can do is use up that day's box searches.
  • If that happens, remove the key and create another.
  • With a Content-Security-Policy, allow https://api.bestastroapi.in in script-src and connect-src.
  • No cookies are used. What the visitor types is sent to our API to find places.
  • Place data: GeoNames, CC BY 4.0, adapted.

For a mobile app, or to keep every request on your server, use place search.

Welcome! How will you use it?

We'll show you what matters to you. You can switch any time at the top.