Instagram user location with api - geolocation

How can i find user location on intagram api ?
instagram endpoints have this uri : https://api.instagram.com/v1/locations/{location-id}?access_token=ACCESS-TOKEN

You can approximate the location of a user by exploiting the location services on the media feed. That is, you can pull the location tag from one or more of the desired user's posted images. You could then use all the user's images to come up with an approximate location or something like that.
Note that not every image has a location tag, and some user's have location services turned completely off, in which case no images will be tagged. But you can do it like this:
using the image id for one of #instagram's images that has a location. then connecting to the instagram api using the python library to get info on that image. then accessing the images location.
image_id = '976907440786573124_25025320'
image_info = api.media(image_id)
lat = image_info.location.point.latitude
lon = image_info.location.point.longitude
print (lat,lon)
gives the result (51.565501504,-0.089821461)

To add on to jstnstwrt's answer, the most direct way is:
If you install the python-instagram libary for python, you can do the following:
import instagram
api = InstagramAPI(access_token=access_token, client_secret=client_secret)
id = <id of the user you're trying to get location from>
location = api.location(id) # returns error if no location set
coordinates = location.point #returns point object with lat and long coordinates
EDIT 25/07/2019:
This has long stopped working, instagram has locked down their APIs significantly. I would recommend something like instaloader (https://pypi.org/project/instaloader/) that works decently.

Related

How to get last picture taken by user/camera

How do I get last picture from gallery (camera roll) using flutter?
I would like to display this photo as a thumbnail like this:
I know that it's possible in android Get uri of picture taken by camera and in IOS Swift - how to get last taken 3 photos from photo library?
Is there a tool, lib, media API that could help me with that?
You can try using this library. photo_manager
List<AssetEntity> assets = [];
_fetchAssets() async {
final albums = await PhotoManager.getAssetPathList(type: RequestType.all);
final recentAlbum = albums.first;
final recentAssets = await recentAlbum.getAssetListRange(
start: 0, // start at index 0
end: 1, // end at a very big index (to get all the assets)
);
print(recentAssets);
setState(() => assets = recentAssets);
}
Use platform channels ,, as you know it's native solution
https://medium.com/flutter-io/flutter-platform-channels-ce7f540a104e
https://flutter.io/docs/development/platform-integration/platform-channels
If you're willing to do this through a dialog, you can use the image picker plugin which allows you to go through the camera's image gallery and the user can select the image (including the last image).
If you want this done completely programmatically, someone implemented a pull request for this very feature here: https://github.com/flutter/plugins/pull/676, but it hasn't been accepted because it needs some tests. You could copy the code from that PR, or add some tests, and then get it accepted into the repo!

Offline geocoding using MBTiles with vector tiles

I load an MBTiles Vector Tile data source of my country, using carto-mobile SDK
// Initialize base layer with a bundled styles
let baseLayer = NTCartoOnlineVectorTileLayer(style: NTCartoBaseMapStyle.CARTO_BASEMAP_STYLE_GRAY)
// Use the style for your own vector tile datasource (online, offline etc),
let tileDataSource = NTMBTilesTileDataSource(path: Bundle.main.path(forResource: "estonia_ntvt", ofType: "mbtiles"))
// Initialize offline layer & Grab vector tile layer from our base layer
let offlineLayer = NTVectorTileLayer(tileDataSource, baseLayer?.getTileDecoder())
mapView?.layers?.add(baseLayer)
mapView?.layers?.add(offlineLayer)
and is showing everything ok, so i have my map and all the features.
So now i want to search, for a POI or a street name.
I know that an MBTiles have all the information inside him, but how can i access to that info??
Is this posible?? if it is possible, how i do that??
The latest version (4.1.0) of CARTO mobile SDK has NTVectorTileSearchService using mbtiles. There is no user doc for it yet, but sample code can be found from AdvancedMap.Swift.
// init search service with your mbtiles
searchService = NTVectorTileSearchService(dataSource: baseSource, tileDecoder: baseLayer.getTileDecoder())
// prepare search request, set some conditions.
// This search is to find attractions within 500m from a route geometry
let request = NTSearchRequest()
request?.setProjection(contentView.baseSource.getProjection())
request?.setGeometry(geometry)
request?.setSearchRadius(500.0)
request?.setFilterExpression("class='attraction'")
// actual search
let results = contentView.searchService.findFeatures(request)
let count = Int((results?.getFeatureCount())!)
// go through found items
for i in 0..<count {
let item = results?.getFeature(Int32(i))!
if (item?.getGeometry() is NTPointGeometry) {
contentView.addPOI(feature: item!)
}
}
Note that this Search service is more usable for POI or street geometry search. Also be aware that same street is often duplicated in different tiles, and big polygons are often partial in tiling.
By geocoding we mean a bit different things - search for human-readable addresses or search for address given a location (reverse-geocode). MBTiles/Vector tiles does not have full data for this, it optimized for visual look. For example building or address points may have house number tag, but almost never have streets or city and country data in them, as it would be redundant and not needed for visual maps. Now for literal geocoding CARTO SDK has solution also: NTGeocodingService. You can use this online or offline, just for the offline case SDK has to download special different data packages per country (or city if you want). These data packages have full hierarchical address data, so real geocoding would work with them. So for complete offline data you would need to get two offline packages separately: mbtiles for maps and geocoding database. If you want offline routing also, then third dataset, as this also cannot be done properly from mbtiles/vector tiles alone.
This is very new feature, so you need to use pre-release version of SDK, but your feedback is very welcome.

How to set path to picture in folder in device in android appcelerator app

So I have app where I want to let users to share screenshot of score to facebook etc... I'm using SocialShare widget. In documentation it says to set path to image like this: "image:fileToShare.nativePath", but I'm not really sure how to set it. Another problem is that I need to share picture that has always different name, it saves screenshots with names like tia7828157.png,tia107997596.png... in folder in device internal memory in pictures/enigmania/ I'm new to appcelerator, so I dont know if there is something like wildcard I could use for this? Thanks for any help.
This is my code so far which I know is wrong, I know the widget works because it shares text without problem:
function shareTextWidget(e){
// share text status
var socialWidget=Alloy.createWidget('com.alcoapps.socialshare');
socialWidget.share({status:"Enigmania kvíz",androidDialogTitle:"hoho",image:test.png/pictures/enigmania});
}
You should use Ti.Filesystem class methods/properties to get the path of any file located on internal or external storage.
Also aware of the permissions of reading storage on Android 6+. Use Storage Permissions before accessing any file on Android 6+.
Simple code snippet to create a directory on internal storage at this location: pictures/enigmania and then write an image file of captured view in this directory.
function shareTextWidget(e){
var directory = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'pictures/enigmania');
!directory.exists() && directory.createDirectory();
var fileToShare = Ti.Filesystem.getFile(directory.resolve(), 'screen.jpg');
fileToShare.write($.SCREENSHOT_VIEW.toImage()); // write the blob image to created file
var socialWidget=Alloy.createWidget('com.alcoapps.socialshare');
socialWidget.share({status:"Enigmania kvíz",androidDialogTitle:"hoho",image:fileToShare.nativePath});
}
This code should work without any issues.
Note that $.SCREENSHOT_VIEW is the View ID for which you will take screenshot, so it depends on you how you maintain your View positions in order to capture correct screenshot, but point is to use Ti.UI.View toImage() method to capture the screenshot of particular view.
Let me know if this works for you or not, else we can look into other methods by getting your exact requirements. Good Luck!!!!

How to show places like "national parks" using google maps sdk in iOS?

I'm using xcode 6.4, Swift and iOS8. My goal is to show a map using the google maps (and places?) sdk. This map should contain all results google delivers when i search for "national park" on google maps.
What I already did is the following:
Create an API Key for iOS at google (places and maps sdk)
Show the map and the users current position
Now I'm struggling in showing the parks when the user opens the map. I already dived around in googles sdk documentation, and came to the conclusion that I'll need the Places SDK for that. But now I'm a bit lost, all I find are scenarios in which the user either has to choose between different "place types" or the app is calling information for one particular place, knowing its id.
After you have the key and every thing you can get places by calling the map api like this. the parameters (format strings are self explanatory) you have to tell the center location by giving latitude longitude (you can get it from users location if you want to show surrounding places). distance is the area for which you want to query for places. types this mention types of places so it canbe parks, restaurants etc.
When you have run the query you will get a list of places with details and the you have to draw using map annotations
var googleURLString NSString(format:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&types=%#&sensor=true&key=%#",latitude, longitute, distance, type, apiKey ) as String
let googleURL = NSURL(string: googleURLString)
let locationData = NSData(contentsOfURL: googleURL!, options: nil, error: nil)
let dataToUse = NSJSONSerialization.JSONObjectWithData(locationData, options: NSJSONReadingOptions.AllowFragments, error:&error) as NSDictionary
let locations = dataToUse["results"]

How to route between two addresses using the new iOS 6.0 maps?

I'm using the iOS 6.0 SDK and I would like to route between two different addresses (not latitude and longitude) with Apple's new iOS 6.0 maps. I would like to show the indications too.
How can I do this?
I looked into do doing this last week and did not figure out a way to do it. It appears that you can give a destination, and you can sort of give it more than just coordinates, but it always assumes your starting position is the current location. That is limiting when you may be planning a trip while you are not currently at the starting location. (But perhaps I am just not seeing how it is done and I hope someone can correct me if that is true.)
A while back I looked into routing options for iOS 6 and gathered the results here...
How would you providing routing for directions between points on a map? What are the missing pieces?
You still may not be able to open up Apple Maps with the exact routing that you want, but perhaps you can draw the route with overlays and annotations on your own instance MKMapView. That may be the best you can do for now.
Below is the code that I used to route to a location and provide at least a label for the destination instead of leaving it to only coordinates. I found that simply giving the destination a label with the full address details would not work, so I just provide that one value.
if (flag != DirectionsFlag_PublicTransit && itemClass && [itemClass respondsToSelector:#selector(openMapsWithItems:launchOptions:)]) {
NSDictionary *address = #{ (NSString *)kABPersonAddressStreetKey : location.title };
MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:location.coordinate addressDictionary:address];
MKMapItem *destinationMapItem = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark];
if (flag == DirectionsFlag_Driving) {
[destinationMapItem openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
else if (flag == DirectionsFlag_Walking) {
[destinationMapItem openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}];
}
}
This code specifically does not handle Public Transit directions since Apple Maps does not do that. I instead have it open up Google Maps with the URL that I was using previously which now opens up Safari for those directions. The flag is an enum value of Driving, Walking or Public Transit. The location is a model which contains various details including title and coordinates.

Resources