1

I'm just starting out with Drupal, and I have no idea what I'm doing.

I already have the postal code which I can convert to latitude and longitude using the Google Geocoding API.

My problem is how to create the fields that will store the latitude and longitude and how to insert those values in the database so that I can use them in a search view which uses the Search API Solr search module.

All I need is for someone to point me out to what I need to do, maybe some tutorials or resources that will enlighten me so that I know what I'm doing. Please help, thanks!

1

Assuming you use Drupal 7, it is trivial to add fields to any entity using the build-in Fields module. (If you see references to "CCK", note that this is not for Drupal 7, but to an older version of this feature.) With fields, you can enhance Drupal 7 with new data types and entity types from the front end admin interface.

The term "field" refers to a given piece of content within an entity. A field is characterised by having a field name, field type and widget. A widget in this context can be a HTML form element or jQuery widget that is to be used for data entry.

To have latitude and longitude fields in your entity, you should install the Geofield module. This will give you access to geofields as native datatypes, and also a widget for entering map coordinates if you need that.

To add fields to an entity, start by navigating to Structure → Content types, and click on manage fields for the content type you want to add new fields to. This can be one of the build-in content types, or a custom content type you've defined.

Clicking on manage fields brings up a form that shows what fields are already present in the entity. Here you can delete or add new fields to the entity. Add your geofields and click Save.

However, if you want to insert values into those fields programatically (instead of interactively using a widget), you need to create a small custom module that uses the Drupal database API to insert the values into the fields in the database.

Here are links to some fields tutorials that tells you more about how to use fields:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.