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
- Create a website key for your domain on the dashboard's API keys page.
- 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, Indiabirthplace_lat,birthplace_lon: coordinatesbirthplace_tz: time zone, for example Asia/Kolkatabirthplace_place_id: send this asplace_idto 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
| Attribute | Where | Meaning |
|---|---|---|
| data-key | script | Your website key. Required |
| data-country | script or field | Two-letter code such as IN, to search one country only |
| data-bestastro-place | field | Turns this text field into a place box |
| data-prefix | field | Start 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-inputkeep working. - They fill the same
coordinatesandtimezonefields. - Code that calls
LocationSearchkeeps 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.ininscript-srcandconnect-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.