Invoking Blackberry Map application with address details - blackberry

I am working with version 4.6 of the blackberry OS.
I am attempting to invoke the Maps application using the following:
Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(MapsArguments.ARG_LOCATION_DOCUMENT, document));
This works fine for an example document such as:
String document = "<lbs>" + "<location lon='-8030000' lat='4326000' label='Kitchener, ON' description='Kitchener, Ontario, Canada' />" + "</lbs>";
My question is: how can I construct such a document if I do not know the coordinates of the location I am trying to inspect? I only know the address...

According to this document, <location> supports an address, city, postal code, and region attributes. Would this work?
If that doesn't work, you'll need to use the Locator class to get the location information. It needs starting coordinates though. Code from page 25 of the documentation:
// Create an javax.microedition.location.AddressInfo object
AddressInfo ai = new AddressInfo();
// Set the fields of the AddressInfo Object
ai.setField(AddressInfo.STREET, “main street”);
ai.setField(AddressInfo.CITY, “Toronto”);
ai.setField(AddressInfo.STATE, “Ontario”);
ai.setField(AddressInfo.POSTAL_CODE, “XXX XXX”);
ai.setField(AddressInfo.COUNTRY, “Canada”);
// Create a Coordinates object that the location-based services locator server
// uses as a starting location to search for location
// information for an address.
Coordinates co = new Coordinates(45.423488, -75.697929, 0);
// Create a Locator object.
Locator lo = new Locator();
// Invoke Locator.geocode(AddressInfo address, Coordinates startCoords).
Enumeration en = lo.geocode(ai, co);

Related

Need to remove numbers with a javascript code step in Zapier

I am not a developer but have used Google search and trial and error test scenarios with Zapier for the last few days and have given up on figuring this out myself. I need help!
I'm using the Run JavaScript code step in Zapier and provided the following details to Input Data.
It says: What input data should we provide to your code (as strings) via an object set to a variable named inputData?
I'm using "street" with a street address example "1402 Spring Garden Rd"
What is the code to use that regardless of the street address provided all the numbers and first space are removed so that the results is "Spring Garden Rd"
Thank you in advance!
var street = inputData;
var streetNoNumbers = inputData.replace(/[0-9]/g, '');
return streetNoNumbers
The error message I'm getting is
TypeError: inputData.replace is not a function
I've learned that strings are immutable and a new string can be made from manipulating another string but doing this in zapier seems to require a function and creating another var with the calculation generates a ... is not a function.
I've tried to write a function but can't get the output or return to show the proper results either.
I can do the following successfully,
var street = inputData
return street
1402 Spring Garden Road
I want to include the code that manipulates street to produce the following:
Spring Garden Road
David here, from the Zapier Platform team. Great question!
The key understanding you're missing is that inputData is a js object with a street property. Before your code is run, we set it up like so:
const inputData = {street: '1402 Spring Garden Rd'}
Since inputData is an object, it doesn't have a replace method (the error you're seeing). Instead, perform your operation on .street and return that.
Try the following:
// need to return an object, not just a string
return {streetNoNumbers: inputData.replace(/[0-9]/g, '')}
If you want to learn more, I recommend our simple examples: https://zapier.com/help/code/#simple-email-extraction

Retrive Lat Long from ZipCode

Is their is a way to get Lat Long from MaxmindDb through ZipCode rather than Ipaddress. As i cannot find any method to fetch details through zipcode. I don't want to use Google Maps Api.
using (var reader = new DatabaseReader(System.Web.Hosting.HostingEnvironment.MapPath("~/GeoLite2-City.mmdb")))
{
var city = reader.City(userIpAddress);
string cityiso = string.Empty;
if (city != null && !string.IsNullOrEmpty(city.City.Name) && !string.IsNullOrEmpty(city.MostSpecificSubdivision.IsoCode))
{
cityiso = string.Join(", ", city.City.Name, city.MostSpecificSubdivision.IsoCode);
}
locationProperties.Location = cityiso;
locationProperties.Latitude = city.Location.Latitude.ToString();
locationProperties.Longitude = city.Location.Longitude.ToString();
}
But I want to use UserZipCode instead of UserIPAddress
From the example in your question I assume you want the look-up table on your own server rather than use any API.
One of the Maxmind Libraries on Github might include this functionality. However Maxmind City DB actually uses Zip Code data from geonames.org and a simpler solution might be to upload the GeoNames "look-up" table Zip for US to your server.
It contains a tab delimited file (see bottom of link for full description) and you would just have to write code to find the record for by zip code and then read the lat and long fields from it. For improved speed you could import the file to a DBMS e.g. mySQL (google for instructions) with zip code as key/indexed.
I've no idea as to preciseness and accuracy of Geonames data.

How can i get all SKMap location objects so I can filter trough them?

I use SKMap in a offline navigation iOS application and:
I'm trying to search from a UITextField a street/city/district within a preinstalled map and I want to get all objects that matches my search.
How can I get all map location objects so I can filter trough them?
From the sample didn't quite managed to do so.(I get only cities)
Is there other alternative or I must loop trough every city and get streets (Seems ugly)
You have to use SKNearbySearchSettings class and to set
searchObject.searchType = SKAll;
A more detailed example of using this class (should return all streets and POIs containing the "pizza" keyword):
SKNearbySearchSettings *searchObject = [SKNearbySearchSettings nearbySearchSettings];
searchObject.coordinate = CLLocationCoordinate2DMake(52.5233, 13.4127);
searchObject.radius = 40000;
searchObject.searchMode = SKSearchHybrid;
searchObject.searchResultSortType = SKMatchSort;
searchObject.searchType = SKAll;
searchObject.searchTerm = "pizza";
[[SKSearchService sharedInstance]startNearbySearchWithSettings:searchObject];

How to get user's geolocation?

On many sites I saw printed out my current city where I am (eg "Hello to Berlin."). How they do that? What everything is needed for that?
I guess the main part is here javascript, but what everything I need for implementing something like this to my own app? (or is there some gem for Rails?)
Also, I would like to ask for one thing yet - I am interesting in the list of states (usually in select box), where user select his state (let's say Germany), according to the state value are in another select displayed all regions in Germany and after choosing a region are displayed respective cities in the selected region.
Is possible anywhere to obtain this huge database of states/cities/regions? Would be interesting to have something similar in our app, but I don't know, where those lists get...
You need a browser which supports the geolocation api to obtain the location of the user (however, you need the user's consent (an example here) to do so (most newer browsers support that feature, including IE9+ and most mobile OS'es browsers, including Windows Phone 7.5+).
all you have to do then is use JavaScript to obtain the location:
if (window.navigator.geolocation) {
var failure, success;
success = function(position) {
console.log(position);
};
failure = function(message) {
alert('Cannot retrieve location!');
};
navigator.geolocation.getCurrentPosition(success, failure, {
maximumAge: Infinity,
timeout: 5000
});
}
The positionobject will hold latitude and longitude of the user's position (however this can be highly inaccurate in less densely populated areas on desktop browsers, as they do not have a GPS device built in). To explain further: Here in Leipzig in get an accuracy of about 300 meters on a desktop computer - i get an accuracy of about 30 meters with my cell phone's GPS device.
You can then go on and use the coordinates with the Google Maps API (see here for reverse geocoding) to lookup the location of the user. There are a few gems for Rails, if you want. I never felt the need to use them, but some people seem to like them.
As for a list of countries/cities, we used the data obtainable from Geonames once in a project, but we needed to convert it for our needs first.
Internet Service Providers buy up big chunks of IP addresses, so what you're most likely seeing is a backtrace your IP to a known ISP. They have a database with ISP's and their location in the world, so they can try to see where you're from. You could try to use a site like http://www.ipaddresslocation.org/ to do your work. If you look around, there is bound to be a site that lets you enter an IP and get a location, so you just send a POST request to that site with your visitor's IP and scrape the location from the response.
Alternatively you could try to look for an ISP database that has location and what chunks of the IP range they have been allocated. You could probably find one for money, but a free one might be harder to find.
Alternatively, check out this free database http://www.maxmind.com/app/geolite
I've found getCurrentPosition() to often be inaccurate since it doesn't spend a lot of time waiting on the GPS to acquire a good accuracy. I wrote a small piece of JavaScript that mimics getCurrentPosition() but actually uses watch position and monitors the results coming back until they are better accuracy.
Here's how it looks:
navigator.geolocation.getAccurateCurrentPosition(onSuccess, onError, {desiredAccuracy:20, maxWait:15000});
Code is here - https://github.com/gwilson/getAccurateCurrentPosition
Correc syntax would be :
navigator.geolocation.getCurrentPosition(successCallBack, failureCallBack);
Use :
navigator.geolocation.getCurrentPosition(
function(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
console.log("Latitude : "+latitude+" Longitude : "+longitude);
},
function(){
alert("Geo Location not supported");
}
);
If you prefer to use ES6 and promises here is another version
function getPositionPromised() {
function successCb(cb) {
return position => cb(position);
}
function errorCb(cb) {
return () => cb('Could not retrieve geolocation');
}
return new Promise((resolve, reject) => {
if (window.navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successCb(resolve), errorCb(reject));
} else {
return reject('No geolocation support');
}
})
}
And you can use it like this:
getPositionPromised()
.then(position => {/*do something with position*/})
.catch(() => {/*something went wrong*/})
Here is an another api to find out the location in PHP,
http://ipinfodb.com/ip_location_api.php
I have been using geoip.maxmind.com for quite a while and it works 100%. It can be accessed via HTTP requests.

How to get/set the bonding box in google map?

How can I get/set the bonding box of a Google map? I know how to create map using center and zoom, but I need a way to save the view of map based on its boxing and the recreate the same view later using the map bonds (NE and SW of map)
Any idea how I can do this?
I am using MVC 3.
You want to use the map.getBounds() function which returns a LatLngBounds object. From this you can then use getNorthEast() and getSouthWest() to get the coordinates you want.
var bounds = map.getBounds();
var NE = bounds.getNorthEast();
var SW = bounds.getSouthWest();
If you need those LatLng objects to then be strings (for inserting to your DB or writing to a cookie or whatever), just use the toString() function on them.
strNE = NE.toString();
strSW = SW.toString();
So let's assume you write these to a cookie or use Ajax to write these to your DB. Once you get them out of the cookie/DB later, you can then just use those for setting the center of the map:
bounds = new google.maps.LatLngBounds(SW, NE);
map.fitBounds(bounds); // or maybe try panToBounds()
All these functions are documented here: https://developers.google.com/maps/documentation/javascript/reference

Resources