EzDevInfo.com

maps interview questions

Top maps frequently asked interview questions

Calculate distance between two latitude-longitude points? (Haversine formula)

How do I calculate the distance between two points specified by latitude and longitude?

For clarification, I'd like the distance in kilometers; the points use the WGS84 system and I'd like to understand the relative accuracies of the approaches available.


Source: (StackOverflow)

What is the ideal data type to use when storing latitude / longitudes in a MySQL database?

Bearing in mind that I'll be performing calculations on lat / long pairs, what datatype is best suited for use with a MySQL database?


Source: (StackOverflow)

Advertisements

Covert latitude/longitude point to a pixels (x,y) on mercator projection

I'm trying to convert a lat/long point into a 2d point so that I can display it on an image of the world-which is a mercator projection.

I've seen various ways of doing this and a few questions on stack overflow-I've tried out the different code snippets and although I get the correct longitude to pixel, the latitude is always off-seems to be getting more reasonable though.

I need the formula to take into account the image size, width etc.

I've tried this piece of code:

double minLat = -85.05112878;
double minLong = -180;
double maxLat = 85.05112878;
double maxLong = 180;

// Map image size (in points)
Double mapHeight = 768.0;
Double mapWidth = 991.0;

// Determine the map scale (points per degree)
double xScale = mapWidth/ (maxLong - minLong);
double yScale = mapHeight / (maxLat - minLat);



// position of map image for point
double x = (lon - minLong) * xScale;
double  y = - (lat + minLat) * yScale;

System.out.println("final coords: " + x + " " + y);

The latitude seems to be off by about 30px in the example I'm trying.Any help or advice?

update

Based on this question:Lat/lon to xy

I've tried to use the code provided but I'm still having some problems with latitude conversion, longitude is fine.

    int mapWidth = 991;
    int mapHeight = 768;

    double mapLonLeft = -180;
    double mapLonRight = 180;
    double mapLonDelta = mapLonRight - mapLonLeft;

    double mapLatBottom = -85.05112878;
    double mapLatBottomDegree = mapLatBottom * Math.PI / 180;
    double worldMapWidth = ((mapWidth / mapLonDelta) * 360) / (2 * Math.PI);
    double mapOffsetY = (worldMapWidth / 2 * Math.log((1 + Math.sin(mapLatBottomDegree)) / (1 - Math.sin(mapLatBottomDegree))));

    double x = (lon - mapLonLeft) * (mapWidth / mapLonDelta);
    double y = 0.1;
    if (lat < 0) {
        lat = lat * Math.PI / 180;
        y = mapHeight - ((worldMapWidth / 2 * Math.log((1 + Math.sin(lat)) / (1 - Math.sin(lat)))) - mapOffsetY);
    } else if (lat > 0) {
        lat = lat * Math.PI / 180;
        lat = lat * -1;
        y = mapHeight - ((worldMapWidth / 2 * Math.log((1 + Math.sin(lat)) / (1 - Math.sin(lat)))) - mapOffsetY);
        System.out.println("y before minus: " + y);
        y = mapHeight - y;
    } else {
        y = mapHeight / 2;
    }
    System.out.println(x);
    System.out.println(y);

When using the original code if the latitude value is positive it returned a negative point, so I modified it slightly and tested with the extreme latitudes-which should be point 0 and point 766, it works fine. However when I try a different latitude value ex: 58.07 (just north of the UK) it displays as north of spain.

Any ideas?


Source: (StackOverflow)

Open alternatives to Google-maps?

I'm looking for an alternative to Google-maps with all the richness of their API but more open. Does such a thing exist?


Source: (StackOverflow)

get boundaries longitude and latitude from current zoom google maps

i need to know long and lat of my four corners of current area as in this image

enter image description here

i have tried this but with no luck :

map.getBounds();

any help ?


Source: (StackOverflow)

Merge two STL maps

How can I merge two STL maps into one? They both have the same key value types (map). If there is overlap of the keys I would like to give preference to one of the maps.


Source: (StackOverflow)

Using custom map image tiles in LeafletJS?

Do my tiles need to adhere to any particular specs?

I have a large image file which I'd like to turn into a map with LeafletJS. I am going to be using the Python Imaging Library to cut it up into all the various tiles I need.

However, I can't find any information about using custom maps in Leaflet. Do I provide Leaflet with the range of X,Y,Z info somehow? Do I give it the pixel size of each tile? Does it figure this out on its own?

To put my question into one concise question: What do I need to do in order to have image files that can double as map tiles with LeafletJS, and what, if anything, do I need to do in my front-end script? (beyond the obvious specifying of my custom URL)


Source: (StackOverflow)

Android Maps Point Clustering

Is there any code for Point Clustering in android? How can i load thousand pinpoint without having performance issues?


Source: (StackOverflow)

google maps android api v2 - detect touch on map

I can't find an example on how to intercept the map touch on new maps api v2.

I need to know when user touches the map in order to stop a thread (the centering of the map around my current location). Please, give me a starting point. Thank you.


Source: (StackOverflow)

using BOOST_FOREACH with std::map

I'd like to iterate over a std::map using BOOST_FOREACH and edit the values. I can't quite get it.

typedef std::pair<int, int> IdSizePair_t;
std::map<int,int> mmap;    
mmap[1] = 1;
mmap[2] = 2;
mmap[3] = 3;
BOOST_FOREACH( IdSizePair_t i, mmap )
    i.second++;
// mmap should contain {2,3,4} here

Of course this doesn't change anything because I'm not iterating by reference. So I substitute this line instead (as per the example in the Boost docs):

BOOST_FOREACH( IdSizePair_t &i, mmap )

and I get the compiler error:

error C2440: 'initializing' : 
cannot convert from 'std::pair<_Ty1,_Ty2>' to 'IdSizePair_t &'
    with
    [
        _Ty1=const int,
        _Ty2=int
    ]

Any suggestions?


Source: (StackOverflow)

Openstreetmap: embedding map in webpage (like Google Maps)

Is there a way to embed/mashup the OpenStreetMap in your page (like the way Google Maps API works)?

I need to show a map inside my page with some markers and allow dragging/zooming around, maybe routing. I suspect there would be some Javascript API for this, but I can't seem to find it.

Searching gets me an API for access to raw map data, but that seems to be more for map editing; besides, working with that would be a heavy task for AJAX.


Source: (StackOverflow)

Google Maps Android API v2 - Sample Code crashes

I'm trying to get the sample code of Android 'Google Maps Android API v2' working. I get the project built without errors. However, when I try to run the app on my Galaxy Nexus (connected with usb to my laptop), the app crashes immediately.

  • I filled in my own Maps API Key at the AndroidManifest.xml
  • I built against Android 4.1.2

This is the logging:

Unable to resolve superclass of Lcom/example/mapdemo/BasicMapActivity; (66) 
Link of class 'Lcom/example/mapdemo/BasicMapActivity;' failed 
Could not find class 'com.example.mapdemo.BasicMapActivity', referenced from method com.example.mapdemo.MainActivity.<clinit> 
VFY: unable to resolve const-class 108 (Lcom/example/mapdemo/BasicMapActivity;) in Lcom/example/mapdemo/MainActivity; 
VFY: replacing opcode 0x1c at 0x000d 
Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/example/mapdemo/MainActivity; 
Class init failed in newInstance call (Lcom/example/mapdemo/MainActivity;) 
Shutting down VM 
threadid=1: thread exiting with uncaught exception (group=0x41ac9930) 
FATAL EXCEPTION: main 
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NoClassDefFoundError: com.example.mapdemo.BasicMapActivity
at com.example.mapdemo.MainActivity.<clinit>(MainActivity.java:97)
... 15 more

Does anybody have a hint how to solve this or what I might be doing wrong?


Source: (StackOverflow)

rgdal package installation

The issue here is not exactly how to plot maps through R, as I have found already a pretty nice example here, but rather how to make it work. In fact, I am unable to load library rgdal:

library(rgdal)
Error in library(rgdal) : there is no package called ‘rgdal’

However, when I try to install the above package manually, I get the following error:

....
configure: error: proj_api.h not found in standard or given locations.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/home/eualin/R/i686-pc-linux-gnu-library/2.15/rgdal’
Warning in install.packages : installation of package ‘/home/eualin/Downloads/rgdal_0.8-5.tar.gz’ had non-zero exit status

Any input welcome!


Source: (StackOverflow)

C++ map access discards qualifiers (const)

The following code says that passing the map as const into the operator[] method discards qualifiers:

#include <iostream>
#include <map>
#include <string>

using namespace std;

class MapWrapper {
public:
    const int &get_value(const int &key) const {
        return _map[key];
    }

private:
    map<int, int> _map;
};

int main() {
    MapWrapper mw;
    cout << mw.get_value(42) << endl;
    return 0;
}

Is this because of the possible allocation that occurs on the map access? Can no functions with map accesses be declared const?

MapWrapper.cpp:10: error: passing ‘const std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >’ as ‘this’ argument of ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = int, _Tp = int, _Compare = std::less<int>, _Alloc = std::allocator<std::pair<const int, int> >]’ discards qualifiers


Source: (StackOverflow)

How to invoke iPhone Maps for Directions with Current Location as Start Address

I know it's possible to start the iPhone maps application by calling openURL on a google maps URL with parameters saddr and daddr with location strings or Lat/Long (see example below).

But I'm wondering if it's possible to make the start address be the "Current Location" maps bookmark so that I can use the Maps app's location handling code. My Google search has been pretty fruitless.

For example:

[[UIApplication sharedApplication] openURL:
    [NSURL URLWithString:
        [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%@&daddr=%@", 
                                    myLatLong, 
                                    latlong]]];

Except with something to invoke the current location bookmark in place of myLatLong.


Source: (StackOverflow)