All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.isuper.telegram.models.Location Maven / Gradle / Ivy

Go to download

A java library which allows you to send messages(for now, more in the future) to telegram chats

There is a newer version: 0.1.24
Show newest version
/**
 * 
 */
package org.isuper.telegram.models;

import org.isuper.telegram.utils.TelegramUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.JsonProcessingException;

/**
 * This object represents a point on the map.
 * 
 * @author Super Wang
 *
 */
@JsonIgnoreProperties(ignoreUnknown=true)
public class Location {

	public final float latitude;
	public final float longitude;
	
	/**
	 * @param latitude
	 * 					Latitude as defined by sender
	 * @param longitude
	 * 					Longitude as defined by sender
	 */
	public Location(float latitude, float longitude) {
		if (Math.abs(latitude) > 90) {
			throw new IllegalArgumentException(String.format("Invalid latitude %f", latitude));
		}
		this.latitude = latitude;
		if (Math.abs(longitude) > 180) {
			throw new IllegalArgumentException(String.format("Invalid longitude %f", longitude));
		}
		this.longitude = longitude;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		try {
			return TelegramUtils.getObjectMapper().writeValueAsString(this);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return "{}";
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy